我是objective C的新手,我需要快速创建一个iPhone应用程序,我使用的是objective C 4.2
我想要有一个弹出窗口,我使用了以下代码:
在.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];代码显示了一个构建错误“预期标识符”,我是不是忘了什么?
谢谢
发布于 2011-11-09 06:41:27
您有一个额外的左方括号'[‘
你需要这样的东西:
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Confirmation"
message:@"confirmed"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[alert show];请注意我添加的 autorelease ]代码,这样您就可以设置自动释放UIAlertView并修复额外的左括号。
发布于 2011-11-09 07:42:32
您有两个错误:
->[<-[UIAlertView alloc:@“确认”消息:@“已确认”委托:自取消按钮标题:@“确定”其他按钮标题:空->,nil<-];
删除它们,只需写下:
[[UIAlertView alloc] initWithTitle:@"Confirmation"
message:@"confirmed"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];如果你没有使用ARC,别忘了在[alert show]之后释放[alert release] (或者在初始化末尾释放autorelease )
https://stackoverflow.com/questions/8058063
复制相似问题