2011-11-08 56 views
0

我新的目标C和我在我需要真正快速创建一个iPhone应用程序的位置,我使用的XCode 4.2UIalert视图不工作

我希望有一个弹出,我使用验证码:

在.H我

#import <AddressBook/AddressBook.h> 
#import <AddressBookUI/AddressBookUI.h> 

,并在.m文件

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Confirmation" 
                message:@"confirmed" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil,nil]; 
          [alert show]; 

鳕鱼e向我展示了一个建筑错误“预期标识符”,我忘记了什么?

感谢

+0

检查括号匹配,parens,大括号只需双击一个,如果有匹配,选择将highlite。很好的快速测试。 – zaph

+0

额外支架。在分配之前删除它们之一。 – Jacob

+0

我的回答有帮助吗? – Oliver

回答

1

您有一个额外的开括号 '['

你需要的东西是这样的:

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Confirmation" 
                message:@"confirmed" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil] autorelease]; 
          [alert show]; 

注意自动释放]代码我加了,这样你设置为自动释放UIAlertView并修复额外的开放式支架。

+0

Xcode 4.2 - 所以我猜测OP的使用ARC,因此autorelease调用是不需要的。 –

+0

好点,然后不需要autorelease,只需删除额外的开放括号=) –

+0

还要注意,他在'otherButtonTitles:'参数上使用了'nil'两次......我怀疑这可能会造成伤害,但这不是好的做法当然 – Matoe

0

你有两个错误:

->[<- [UIAlertView中页头] initWithTitle:@ “确认” 消息:@ “证实” 委托:自我 cancelButtonTitle:@ “OK” otherButtonTitles:无->,nil<-];

删除它们,只是写:

[[UIAlertView alloc] initWithTitle:@"Confirmation" 
          message:@"confirmed" 
          delegate:self 
       cancelButtonTitle:@"OK" 
       otherButtonTitles:nil]; 

如果你不使用ARC,不要忘记[alert show]后释放[alert release](或autorelease在初始化结束)