Iphone NSString超出范围问题
我的代码是:Iphone NSString超出范围问题,iphone,Iphone,我的代码是: - (void)viewDidLoad { [super viewDidLoad]; self.appDelegate=[[UIApplication sharedApplication]delegate]; self.dateString=[NSString stringWithFormat:@"%@",appDelegate.tappedDate]; dateLabel.text=dateString; } -(IBAction)checkFo
- (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];
}
}
字符串dateString在if条件下超出范围,但它正在标签上显示数据。首先,
bday
永远不会等于dateString
,因为==
会比较两个对象的地址。如果要比较实际字符串,需要执行If([bday isEqualToString:dateString]){…}
关于超出范围的消息:
dateString
的属性是什么样子的?你需要提供更多的细节。通常,它应该看起来像@property(非原子,复制)NSString*dateString
首先,bday
永远不会等于dateString
,因为==
比较两个对象的地址。如果要比较实际字符串,需要执行If([bday isEqualToString:dateString]){…}
关于超出范围的消息:
dateString
的属性是什么样子的?你需要提供更多的细节。通常,它应该看起来像@property(nonatomic,copy)NSString*dateString
appDelegate.tappedDate超出了范围。您知道您无法将两个NSString与=
进行比较吗?您必须使用IseQualtString:
。appDelegate.tappedDate超出范围。您知道您无法将两个NSString与=
进行比较吗?您必须使用IsequalString:
。