Reputation: 7792
So I'm following this tutorial to create a custom UITableCellView
using the interface builder. I created a xib file with a UITableViewCell
that has a custom UITableViewCell
as its class. In said class I have -
@interface SearchResultCell : UITableViewCell
@property(strong,nonatomic)IBOutlet UIImageView *restaurantImage;
@property(strong,nonatomic)IBOutlet UILabel *restaurantName;
@end
In the interface builder file for the custom UITableViewCell
, in the connections menu I dragged restaurantImage
to the UIImageView
in the custom UITableViewCell
, and the label to the restaurantName
.
Then in the place where my table is drawn I do this -
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SearchResultCell *cell = [self.resultTable dequeueReusableCellWithIdentifier:CellTableIdentifier];
NSDictionary *rowData = self.resultsTuples[indexPath.row];
NSString* restaurantTitle = rowData[@"$element"][@"Title"];
cell.restaurantName.text = restaurantTitle;
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"SearchResultCell"
bundle:nil];
[self.resultTable registerNib:nib forCellReuseIdentifier:CellTableIdentifier];
// Do any additional setup after loading the view.
}
Doing cell.restaurantName.text = restaurantTitle
doesn't result in anything. However, doing cell.textLabel.text = restaurantTitle
does work.
Why is my label not updating?
Upvotes: 0
Views: 99
Reputation: 104082
The cells may not be the correct height to show your custom label. Since you made the cells 245 points high in the xib, you should implement tableView:heightForRowAtIndexPath:, and return 245.
Upvotes: 0
Reputation: 1428
Are you do this?
@synthesize restaurantImage;
@synthesize restaurantName;
After that, in your code:
restaurantName = [[UILabel alloc]initWithFrame:yourRestaurantNameFrame];
//other attribute
[self.contentView addSubview:restaurantName];
Upvotes: 0