“无法识别的选择器”在“保存”上按钮?
你能帮我理解一个错误吗?我的项目是一个出现的 modalController,让用户在 mutableArray 中保存新文本。
我从调试器收到此错误:
2011-07-21 16:53:52.362 aeffa[18089:207] -[__NSArrayI addObject:]:无法识别的选择器发送到实例 0x4b042d0
我检查了代码,但我看不出出了什么问题:“取消”按钮工作正常,但“保存”按钮会引发错误。这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(cancel:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self
action:@selector(save:)] autorelease];
}
和方法:
- (IBAction)cancel:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction) save:(id)sender{
Website *newSite = [[Website alloc]init];
NSURL *newURL = [[NSURL alloc ]initWithString:url.text];
newSite.websiteURL = newURL;
newSite.websiteTitle = titre.text;
newSite.websiteDesc = descr.text;
[tabWebSites addObject:newSite];
[newURL release];
[newSite release];
}
谢谢
保罗
could you help me to understand an error? my project is a modalController that appears and let the user save a new text in a mutableArray.
I receive this error from the debugger :
2011-07-21 16:53:52.362 aeffa[18089:207] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x4b042d0
I checked the code but i can't see what's wrong : the "cancel" button works fine, but the "save" button launches the error. Here's my code :
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(cancel:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self
action:@selector(save:)] autorelease];
}
and the methods :
- (IBAction)cancel:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction) save:(id)sender{
Website *newSite = [[Website alloc]init];
NSURL *newURL = [[NSURL alloc ]initWithString:url.text];
newSite.websiteURL = newURL;
newSite.websiteTitle = titre.text;
newSite.websiteDesc = descr.text;
[tabWebSites addObject:newSite];
[newURL release];
[newSite release];
}
Thanks
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您的 tabWebSites 实际上是一个 NSArray 对象......它没有 addObject: 方法。确保它是
NSMutableArray
(您可能将其分配为NSArray
,即使它可能被声明为NSMutableArray
)。I believe your
tabWebSites
is actually anNSArray
object.. which doesn't have aaddObject:
method. Make sure it'sNSMutableArray
(you probably allocate it as aNSArray
, even if it might be declared asNSMutableArray
).