2012-01-23 3 views
0

У меня есть проблема с моей пользовательской ячейкой tableview. Когда я хочу поместить текст на свои ярлыки, это не изменится. Вот как выглядит мой код.Пользовательский UITableviewCell не устанавливает метку

мой NieuwsTableViewCell.h

@interface NieuwsTableViewCell : UITableViewCell{ 

} 
@property (nonatomic, retain) IBOutlet UILabel *topic; 
@property (nonatomic, retain) IBOutlet UILabel *omschrijving; 

@end 

мой NieuwsTAbleViewCell.m

@implementation NieuwsTableViewCell 
@synthesize topic; 
@synthesize omschrijving; 

и мой 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; 
} 

ответ

1

Это потому, что вы устанавливаете свойство текста внутри если (! cell) блок. Этот блок будет вызываться только несколько раз, чтобы создать повторно используемые объекты. Проще говоря, перемещайте ячейку. *. Text = часть вне блока if (! Cell). Вот полный код JIC

- (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]]) 
      { 
      cell = (NieuwsTableViewCell*)view; 
      } 
     } 
    } 
       NSDictionary *info = [json objectAtIndex:indexPath.row]; 

      cell.topic.text = @"Stef"; 
      cell.omschrijving.text = [info objectForKey:@"Nie_omschrijving"]; 
      NSLog(@"voorlopige test"); 

    return cell; 
} 
+0

It Works! Спасибо ! – steaphann

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