Hi!
I have created a very simple application where I am trying to insert a custom cell in a table view. However, whenever I return an instance of the Custom Cell, one nothing is displayed on the screen and second, the application enters some kind of weird infinite loop. Any help would be much appreciated. I have attached my code in this question.
-- view controller which is returning custom cells ---
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Try to recover a cell from the table view with the given identifier, this is for performance
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
// If no cell is available, create a new one using the given identifier
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"sample_1ViewController" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[CustomCell class]])
{
cell = currentObject;
break;
}
}
}
// Fill the cell
cell.lbl.text = @"test";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}
--- custom cell class ---
@interface CustomCell : UITableViewCell {
IBOutlet UILabel * lbl;
}
@property (nonatomic, retain) IBOutlet UILabel * lbl;
@end
@implementation CustomCell
@synthesize lbl;
@end
----
The custom cell is a UITableCellView resource in the sample_1ViewController.xib file. It contains a UILabel. The identifier for the CustomCell is CustomCell as well.
Please see if you could locate something which might be wrong or tell me of something which I am possibly missing out.
Regards Nitin