iOS6 UIAlertView.title坏了吗?

时间:2012-09-25 23:08:07

标签: uialertview title ios6

今天对我来说充满惊喜......以下简单的代码无效。它永远不会进入if语句中的块,即使NSLog将title属性显示为匹配if条件。我今天疯了......

-(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"]) {

然后它运作正常。

1 个答案:

答案 0 :(得分:0)

你正确地做了但是有一个小问题 - 正确的代码将是 -

 -(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:  
  (NSInteger)buttonIndex
    {
        NSLog(@"%@", alertView.title);

       if ([alertView.title isEqualToString:@"Warehouse"])

        {
          // Now it will go inside this condition
        }
   } 

现在它适合你。