2014-02-12 5 views
0

У меня возникла проблема с отображением данных в созданном мной UITableViewCell.Ячейки базовых данных не обновляются правильно

У меня есть модель CoreData, у которой есть пользовательская ячейка, которую я загружаю из Xib. Макет правильно загружается и генерируется правильное количество ячеек. Проблема возникает при обновлении button.titleLabel.text и описания.

Вот мой 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 не обновляется!

Что я делаю неправильно?

ответ

3

Использование

[cell.button setTitle: pointsText forState: UIControlStateNormal]; 

вместо

[cell.button.titleLabel setText:pointsText]; 

Примечание: надежда cell.button является UIButton

+0

Thankyou, что ответили на мой вопрос. ! – jimbob

+0

Тогда вы должны принять ответ @ Akhilrajtr ... – Moonwalkr

+0

ему ответили так быстро, что он не позволил мне принять. – jimbob

Смежные вопросы