I have a UILabel that is loaded form a text file. Sometimes the text file has something in it and sometimes it is empty. So sometimes the UILabel is blank and sometimes it has text in it.
I want to write an if statement that says if the UILabel is blank do one thing else if it has text in it do another thing.
I have tried
if (self.label.text = NULL)
and
if (self.label.text = @"")
but it isn’t working correctly.
With the if (self.label.text = @""), I get the if statement to happen but the else statement doesn’t work.
Here is my code
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;
}
What you are doing is comparing pointers, which doesn’t work with strings. Use this