Kevinflo
Kevinflo

Reputation: 33

Custom cell and UITableViewCell problems

Newbie here, just learning!

I'm trying to create a table view app with just three custom cells. Each cell needs to have an a label and an image on the left (so far I've only bothered with the label part). So far this guide

has been very useful. I created an array with three items and got it to load just fine, but when I tried to implement a custom cell everything broke. For this portion of code:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil){
        NSArray *topLevelObjects = [[NSBundle mainBundle]
                                    loadNibNamed:@"CustomCell"
                                    owner:nil options:nil];

        for(id currentObject in topLevelObjects)
            {
                if ([currentObject isKindOfClass:[UITableViewCell class]])
                {
                    cell = (CustomCell *) currentObject;
                    break;
                }
        }
    }

    cell.issue.text = array objectAtIndex:[indexPath.row];

    return cell;
}

I get the errors Unused variable CellIdentifier, CustomCell undeclared, Expected expression before ) token and Control reaches end of non-void function.

I don't know what would cause these and I'm kind of at a dead end as far as my knowledge of what to look for. Sorry for my newbness, and any pointing in the right direction would be appreciated.

edit: Heyooo! Thanks, importing CustomCell fixed a ton of the problems! Now there are no visible errors before running it, but when I try and run it, I just get sent to

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [array count];

with a red arrow pointing to return [array count];

The current array code I have is:

- (void)viewDidLoad {
    [super viewDidLoad];

    array = [[NSMutableArray alloc] init];
    [array addObject:@"Eleven"];
    [array addObject:@"Ten"];
    [array addObject:@"Nine"];

Wow, what a helpful and responsive community. Can't thank you enough.

Upvotes: 1

Views: 707

Answers (2)

dredful
dredful

Reputation: 4388

You probably just missed a step. Have you made CustomCell.m, CustomCell.m and CustomCell.xib files? If so, you will need to import the header file.

#import "CustomCell.h"

Upvotes: 0

mbykov
mbykov

Reputation: 174

All you need is import declaration of CustomCell class.

#import "CustomCell.h" // for example.

Upvotes: 3

Related Questions