【问题标题】:How to check if a key has no value如何检查键是否没有值
【发布时间】:2015-01-27 10:47:47
【问题描述】:

我有两个提要,我想用它们的内容来填充表格视图,但是当我想显示图像时,键是不同的,所以在 cellForRowAtIndexPath 我有:

 if ([[stories objectAtIndex:storyIndex] objectForKey:@"url"] ==nil) {
        [cell.imag setImageWithURL:[NSURL URLWithString:[[stories objectAtIndex:storyIndex] objectForKey:@"_text"]] placeholderImage:[UIImage imageNamed:@"Alb.png"]];
    }

    else
        [cell.imag setImageWithURL:[NSURL URLWithString:[[stories objectAtIndex:storyIndex] objectForKey:@"url"]] placeholderImage:[UIImage imageNamed:@"Alb.png"]];

但它不起作用。

【问题讨论】:

  • 使用这段代码 if ([dictionary objectForKey:key]) { // contains object}
  • 放断点打印控制台中的值 [stories objectAtIndex:storyIndex] objectForKey:@"url"] 打印什么值....

标签: ios objective-c uitableview key feed


【解决方案1】:

使用此代码

if ([dictionary objectForKey:key]) {
// contains object
}
else
{
//no object
}

【讨论】:

    猜你喜欢
    • 2019-06-26
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    相关资源
    最近更新 更多