如何检查密钥是否没有值

时间:2015-01-27 10:47:47

标签: ios objective-c uitableview key feed

我有两个Feed,我希望它们的内容填充表视图,但是当我想显示图像时,键是不同的,所以在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"]];

但它不起作用。

1 个答案:

答案 0 :(得分:1)

使用此代码

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