如果value = <null> </null>,则无法删除文本显示

时间:2011-06-01 13:38:36

标签: objective-c cocoa-touch ios null uilabel

我试图通过以下代码在标签中显示一些文字:

if (thisPhoto.userBio != NULL)
{
   thisUserBioLabel.text = [NSString stringWithFormat:@"%@",thisPhoto.userBio];
} 
else
{
   thisUserBioLabel.text = @"";                
}

但是,如果thisPhoto.userBio的值等于NULL,则无法移除显示。我尝试使用NSLog(@"%@", thisPhoto.userBio)打印该值,并获得值<null>。我如何修改上面的代码,以便在值为<null>时不会显示消息?

2 个答案:

答案 0 :(得分:4)

当值为<null>而不是NSNull时,会发生

nil。为此,您需要在第一个if。

中添加额外的支票

if (thisPhoto.userBio && ![thisPhoto.userBio isEqual:[NSNull null]])

这将检查两种情况。

答案 1 :(得分:1)

尝试使用if thisPhoto.userBio == NULL ..

   thisUserBioLabel.text = nil;
相关问题