【问题标题】:UILabel in a Prototype Cell is not updated from code原型单元中的 UILabel 未从代码更新
【发布时间】:2012-08-29 11:05:14
【问题描述】:

我在故事板中设计的原型单元中有 2 个UILabels。两者都有其指定的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;           
}

有人熟悉这个问题吗?

我做错了吗?

【问题讨论】:

    标签: ios uitableview storyboard uilabel


    【解决方案1】:

    请检查contentObject.contentType是否不为空。

    【讨论】:

    • contentObject.contentType 不是 NULL(我 NSLogged 它),而 typeLabel.text 是 NULL。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多