iOS6 UIAlertView.title坏了?
问题描述:
对我来说,今天充满了惊喜...下面的简单代码不起作用。它永远不会进入if语句中的块,即使NSLog显示title属性匹配条件。今天疯狂我要去....iOS6 UIAlertView.title坏了?
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"%@", alertView.title);
if (alertView.title == @"Warehouse") {
//.... never get in here even though NSLog above returns "Warehouse"
编辑: 我想通了。在这里回答这个以防万一它能帮助其他人。
显然iOS 6比较字符串或更加严格。 ==用于在iOS 5中正常工作,但在iOS 6中,我不得不使用
if ([alertView.title isEqualToString:@"Warehouse"]) {
然后它工作正常。
答
你正在做正确,但有一个小问题 - 正确的代码将是 -
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:
(NSInteger)buttonIndex
{
NSLog(@"%@", alertView.title);
if ([alertView.title isEqualToString:@"Warehouse"])
{
// Now it will go inside this condition
}
}
现在,它会为你工作。
谢谢 - 哇,这是烦人的。 –