【问题标题】:Added a IBOutlet and Custom TableViewCell doesn't work anymore添加了 IBOutlet 和自定义 TableViewCell 不再起作用
【发布时间】:2012-08-13 11:33:42
【问题描述】:

我刚刚在我的故事板中的UIImageView 中添加了一个IBOutlet,现在我的自定义TableViewCell 不再起作用了。

2012-08-13 13:30:28.052 Project[6189:fb03] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TableViewController 0x808ab80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageView.'


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

static NSString *CellIdentifier = @"CustomCell";
static NSString *CellNib = @"CustomCell";

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
    cell = (CustomCell *)[nib objectAtIndex:0];
}
...
}

有什么建议吗?

【问题讨论】:

    标签: objective-c ios xcode uitableview uikit


    【解决方案1】:

    这是我的应用外观。我使用动态原型表和自定义单元格。

    我的故事板如下所示。

    关键是你应该如下设置图像视图的标签

    不要忘记将单元格标识符设置为与代码中相同。代码如下:

        UIImageView *imageView = (UIImageView *)[cell viewWithTag:5];
        imageView.image = [UIImage imageNamed:@"foo.jpg"];
    

    【讨论】:

    • 我的 TableViewCell 是自定义的。更高,10 个标签,4 个图片。 UILabel 奥特莱斯正在工作。 UIImageView 没有。这是我的问题。
    • 对不起,我误解了你的情况。现在我展示我的应用程序的一部分。希望对您有所帮助。
    • 感谢这项工作。但我仍然不明白为什么我不能将 IBOutlet 用于 UIImageView。这令人困惑
    • 根据我的经验,在使用情节提要时,[[UIImage alloc] init...] 根本不起作用。我认为情节提要可能会初始化图像视图。这很方便,但很难理解。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    相关资源
    最近更新 更多