Date related IF statement ignoring button for some reason
Trying to compare a date (shown in a label, ''fed'' by an NSDate) and a string I've specified in order to disable a button. The label shows the date correctly and there are no fatal errors but the button is unaffected. Any thoughts? I know this may seem basic so I apologise; I've only been learning a couple of weeks in spare time from various tutorials - seems like a gi开发者_Go百科ant learning curve.
-(IBAction) pushCurrentTime; {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //NSDate from date
[dateFormatter setDateFormat:@"EEE"];
labelDate.text = [dateFormatter stringFromDate:[NSDate date]];
NSString *daytocompare = @"Sun";
labelShows.text =daytocompare;
if([daytocompare isEqualToString:labelDate.text]) {
buttontosatnoon.enabled = NO;
}
else{
buttontosatnoon.enabled = YES;
Can see the date in the labels so I know its getting those but for some reason the button remains just the same so wondering if does the 'If' statement need to be expressed differently? Any information is very much appreciated, thank you :)
If buttontosatnoon
is an outlet (ie, the button wasn't created in code), are you sure it's connected in Interface Builder? Are you sure the button's string is @"Sun"? If you set a breakpoint in the -pushCurrentTime: method and debug (you are making use of the debugger, right?), are you sure none of your outlets are nil and the strings equal what you think they do?
精彩评论