我在我创建的UITableViewCell中显示数据时遇到问题。
我有一个CoreData模型,我有一个自定义的Cell,我从Xib加载。布局正确加载并生成正确的单元格数。更新button.titleLabel.text和description时出现问题。
这是我的uitableview和uitableviewcell相关代码:
#pragma mark - UITableViewDatasource Methods.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [pointsHistoryItems count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
PointsHistoryItemCell* cell = (PointsHistoryItemCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return [self createCustomCell:cell cellForRowAtIndexPath:indexPath];
}
- (PointsHistoryItemCell *)createCustomCell:(PointsHistoryItemCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (cell == nil)
{
cell = (PointsHistoryItemCell *)[[[NSBundle mainBundle] loadNibNamed:@"PointsHistoryItemCell" owner:self options:nil] objectAtIndex:0];
}
AwesomePointsHistoryItem *aphi = (AwesomePointsHistoryItem *)[pointsHistoryItems objectAtIndex:indexPath.row];
cell.description.text = aphi.description;
NSString* pointsText = [NSString stringWithFormat:@"%@ Points", [aphi.points stringValue]];
[cell.button.titleLabel setText:pointsText];
NSLog(@"is reaching createCustomCell");
NSLog(@"points %@", cell.button.titleLabel.text);
return cell;
}
日志打印:
is reaching createCustomCell
points 600 Points
然而.. cell.button.titleLabel.text不会更新!
我做错了什么?
答案 0 :(得分:3)
使用
[cell.button setTitle: pointsText forState: UIControlStateNormal];
而不是
[cell.button.titleLabel setText:pointsText];
注意:希望cell.button是UIButton