如何检查键是否没有值

How to check if a key has no value

我有两个提要,我想用它们的内容来填充 table 视图,但是当我想显示图像时,键是不同的,所以在 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
}
else
{
//no object
}