“无法识别的选择器”在“保存”上按钮?

发布于 2024-11-25 17:56:07 字数 1738 浏览 2 评论 0原文

你能帮我理解一个错误吗?我的项目是一个出现的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光礼记 2024-12-02 17:56:07

我相信您的 tabWebSites 实际上是一个 NSArray 对象......它没有 addObject: 方法。确保它是 NSMutableArray (您可能将其分配为 NSArray,即使它可能被声明为 NSMutableArray)。

I believe your tabWebSites is actually an NSArray object.. which doesn't have a addObject: method. Make sure it's NSMutableArray (you probably allocate it as a NSArray, even if it might be declared as NSMutableArray).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文