【发布时间】:2011-09-07 08:34:15
【问题描述】:
我正在尝试实现以下代码但没有成功。基本上,如果不是“空白”,我想将显示名称设置为使用thisPhoto.userFullName,否则显示thisPhoto.userName。
UILabel *thisUserNameLabel = (UILabel *)[cell.contentView viewWithTag:kUserNameValueTag];
NSLog(@"user full name %@",thisPhoto.userFullName);
NSLog(@"user name %@",thisPhoto.userName);
if (thisPhoto.userFullName && ![thisPhoto.userFullName isEqual:[NSNull null]] )
{
thisUserNameLabel.text = [NSString stringWithFormat:@"%@",thisPhoto.userFullName];
}
else if (thisPhoto.userFullName == @"")
{
thisUserNameLabel.text = [NSString stringWithFormat:@"%@",thisPhoto.userName];
}
目前,即使userFullName为空白,我的userName仍然没有显示在屏幕上。
【问题讨论】:
-
请记住,如果您将
==与对象一起使用,它会比较它们的指针。有关您应该使用的方法的更多详细信息,请参见下文。
标签: objective-c cocoa-touch ios uilabel string-comparison