我有一个从文本文件加载的 UILabel。有时文本文件中有一些东西,有时它是空的。所以有时 UILabel 是空白的,有时它里面有文本。
我想写一个 if 语句,说如果 UILabel 是空白的,如果它有文本做另一件事做另一件事。
我试过了
if (self.label.text = NULL)
和
if (self.label.text = @"")
但它不能正常工作。
使用if (self.label.text = @"")
,我得到了 if 语句,但 else 语句不起作用。
这是我的代码
NSString *stuff3 = @"/Stuff";
NSString *titleName = [familyDictionary objectForKey:@"identity"];
NSArray *paths3 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory3 = [paths3 objectAtIndex:0];
NSString *stuffPath3 = [documentsDirectory3 stringByAppendingPathComponent:stuff3];
NSString *fullPath3 = [stuffPath3 stringByAppendingPathComponent:titleName];
self.title = [NSString stringWithContentsOfFile:fullPath3 encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"full path 3 >>>%@",fullPath3);
NSString *stuff4 = @"/Stuff/Objects";
NSString *textName3 = [familyDictionary objectForKey:@"identity"];
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory2 = [paths2 objectAtIndex:0];
NSString *stuffPath = [documentsDirectory2 stringByAppendingPathComponent:stuff4];
NSString *fullPath2 = [stuffPath stringByAppendingPathComponent:textName3];
self.wordlabel.text = [NSString stringWithContentsOfFile:fullPath2 encoding:NSUTF8StringEncoding error:NULL];
//Now load the image at fullPath and install it into our image view's image property.
NSLog(@"full path 3 >>>%@",fullPath2);
if(self.wordlabel.text = @"")
{
[textView setTitle:[NSString stringWithContentsOfFile:fullPath3 encoding:NSUTF8StringEncoding error:NULL] forState:UIControlStateNormal] ;
textView.titleLabel.adjustsFontSizeToFitWidth = TRUE;
}
else
{
[textView setTitle:[NSString stringWithContentsOfFile:fullPath2 encoding:NSUTF8StringEncoding error:NULL] forState:UIControlStateNormal] ;
textView.titleLabel.adjustsFontSizeToFitWidth = TRUE;
}