Reputation: 231
My code is:
- (void)viewDidLoad {
[super viewDidLoad];
self.appDelegate=[[UIApplication sharedApplication]delegate];
self.dateString=[NSString stringWithFormat:@"%@",appDelegate.tappedDate];
dateLabel.text=dateString;
}
-(IBAction)checkForData:(id)sender{
NSString *bday=@"2012-01-26";
if(bday==dateString)
{
UIAlertView *bdayView=[[UIAlertView alloc]initWithTitle:@"Birthday!!!" message:@"Its ur Best Friend's Bday" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[bdayView show];
[bdayView release];
}
else{
UIAlertView *bdayView=[[UIAlertView alloc]initWithTitle:@"No Data" message:@"No Data available for this date" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[bdayView show];
[bdayView release];
}
}
The String dateString is going out of scope in the if condition but it is displaying data on the label.
Upvotes: 1
Views: 59
Reputation: 14169
First of all, bday
will never equal dateString
, as ==
compares the addresses of both objects. If you want to compare the actual strings, you need to do if ([bday isEqualToString:dateString]) {...}
Regarding the out-of-scope message: How does the property for dateString
look like? You need to provide more details. Commonly, it should look like @property (nonatomic, copy) NSString *dateString
Upvotes: 4