自定义视图不更新

时间:2013-12-14 05:41:31

标签: ios iphone objective-c

所以我按照本教程使用界面构建器创建自定义UITableCellView。我创建了一个xib文件,其中UITableViewCell具有自定义UITableViewCell作为其类。在上课时我有 -

@interface SearchResultCell : UITableViewCell
@property(strong,nonatomic)IBOutlet UIImageView *restaurantImage;
@property(strong,nonatomic)IBOutlet UILabel *restaurantName;
@end

在自定义UITableViewCell的界面构建器文件中,我在连接菜单中将restaurantImage拖到自定义UIImageView中的UITableViewCell,并将标签拖到{ {1}}。

然后在我的桌子绘制的地方我这样做 -

restaurantName

执行 -(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. } 不会产生任何结果。但是,执行cell.restaurantName.text = restaurantTitle确实有效。

为什么我的标签没有更新?

2 个答案:

答案 0 :(得分:0)

  1. 你这样做吗?

    @synthesize restaurantImage;
    @synthesize restaurantName;
    
  2. 之后,在您的代码中:

    restaurantName = [[UILabel alloc]initWithFrame:yourRestaurantNameFrame];
    //other attribute
    [self.contentView addSubview:restaurantName];
    

答案 1 :(得分:0)

单元格可能不是显示自定义标签的正确高度。由于你在xib中使单元格高出245点,你应该实现tableView:heightForRowAtIndexPath:,并返回245.

相关问题