objective-c - 检查对象实例的属性是否为 'blank'

标签 objective-c cocoa-touch ios uilabel string-comparison

我试图实现下面的代码但没有成功。基本上,我想将显示名称设置为使用 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仍然没有显示在屏幕上。

最佳答案

我更愿意

if([thisPhoto.userFullName length])

关于objective-c - 检查对象实例的属性是否为 'blank',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6219617/

相关文章:

objective-c - 代码。关于语法错误检查的问题

iphone - 如何将模态视图添加到当前 View Controller 上?

objective-c - iOS NSComparisonresult 问题

objective-c - NSTextField - *textField 内的操作

ios - Evernote:如何获取笔记的上传进度?

iphone - 如何检查用户是否在 iOS 设备上启用了 PIN 码

ios - 仅从 UIView 的 3 个侧面绘制阴影

iphone - xcode iphone 阻止应用程序后台运行?

ios - 从父级重新加载 TableViewController

ios - "ld: file not found: -Obj-C"尝试将 Cordova 添加为组件 (Cleaver)