2011-07-21 7 views
0

エラーを理解するのを手伝ってもらえますか?私のプロジェクトは現れるmodalControllerで、mutableArrayに新しいテキストを保存させます。
Iデバッガからこのエラーを受け取る:「保存」ボタンの「認識できないセレクタ」?

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]; 
      } 

おかげ

ポール

+0

どのように 'tabWebSites'を初期化しますか? – albertamg

答えて

1

私はあなたが実際にtabWebSitesaddObject:を持っていないNSArrayオブジェクト...であると考えています方法。 NSMutableArrayであることを確認してください(NSMutableArrayと宣言されていても、おそらくNSArrayとして割り当てます)。

+0

ありがとう、そこには警告がありました。私はそれを変更しましたが、まだエラーがあります:認識できないセレクタがインスタンス0x4e16e00に送信されました '...私は使用します:modal.tabWebSites = self.tabWebsites; RootVCで、そしてModalVCの上のコード(私の最初の投稿)。あなたは私がバグを見つけるために何ができるのか知っていますか? – Paul

+0

RootVCから設定しているので、RootVCクラスでどのように初期化されているかチェックする必要があります。そうでなければ、ModalVCからtabWebsitesをRootVCのtabWebsitesの 'mutableCopy'として設定することができます(例:modal.tabWebSitesのプロパティが' retain'の場合、 'modal.tabWebSites = [[self.tabWebsites mutableCopy] autorelease] ; ')。ただし、mutableCopyを作成すると、コードでうまく動作しない可能性があります(RootVC tabWebsitesも変更したい場合) –

+0

'RootViewController:43':' self.tabWebsites = mutArray; // [NSArray arrayWithArray:mutArray]; ' (以前に何がコメントされたか) –

関連する問題