原型单元格中的UILabel未从代码更新

时间:2012-08-29 11:05:14

标签: ios uitableview storyboard uilabel

我在故事板中设计的Prototype Cell中有2 UILabel个。两者都有指定的tag号码(1000和1001)。当我编写tableView cellForRowAtIndexPath:方法时,似乎其中一个标签正在接收相关的NSString,而另一个标签则没有。

以下是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {           

    static NSString *CellIdentifier = @"ContentCell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    ContentObject * contentObject =  [contentPackageManager.contentObjectsArray objectAtIndex:[indexPath row]];
//contentPackageManager is a class that holds an NSArray of ContentObjects (it does a few other things, but they are not relevant for this method...)
//ContentObject is a class that holds several attributs such as: NSString*name, NSString*type, etc...

    UILabel *nameLabel = (UILabel *)[cell viewWithTag:1000];
    nameLabel.text = contentObject.name; //this line works OK

    UILabel * typeLabel = (UILabel *)[cell viewWithTag:1001]; 
    typeLabel.text = contentObject.contentType; //this is the PROBLEMATIC one - no effect on the actual UILabel

    return cell;           
}

是否有人熟悉此问题?

我做错了吗?

1 个答案:

答案 0 :(得分:0)

请检查contentObject.contentType是否为空。