2012-01-23 11 views
0

私のカスタムテーブルビューセルに問題があります。テキストを自分のラベルに貼りたいときは変わらない。これが私のコードの様子です。カスタム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

あなたは内部のテキストプロパティを設定しているからですif(!cell)ブロック。そのブロックは、再利用可能なオブジェクトを作成するためにしか呼び出されません。簡単な方法で入力するには、セルを移動します。*。text = if(!セル)ブロックの外側の部分。ここに完全なコードがあります。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

関連する問題