I have a problem with my custom tableview cell. When I want to put text on my labels, it doesn’t change. This is how my code looks like.
my NieuwsTableViewCell.h
@interface NieuwsTableViewCell : UITableViewCell{
}
@property (nonatomic, retain) IBOutlet UILabel *topic;
@property (nonatomic, retain) IBOutlet UILabel *omschrijving;
@end
my NieuwsTAbleViewCell.m
@implementation NieuwsTableViewCell
@synthesize topic;
@synthesize omschrijving;
and my firstViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NieuwsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"NieuwsTableViewCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.topic.text = @"Stef";
cell.omschrijving.text = [info objectForKey:@"Nie_omschrijving"];
NSLog(@"voorlopige test");
cell = (NieuwsTableViewCell*)view;
}
}
}
return cell;
}
It is because you’re setting the text property inside the if (!cell) block. That block will only be called few times to create the reusable objects. To put it in a simple way move the cell.*.text = part outside of the if (!cell) block. Here’s a complete code JIC