2011-01-20 9 views
0

私は、モーダルビューのボタンをクリックすることに基づいてsplitviewコントローラのビューを変更しようとしています(人はオプションを選択しています)。私はこれを達成するために、通知を使用しています:splitviewcontrollerのビューを変更できません

[[NSNotificationCenter defaultCenter] postNotificationName::それは通知を発行し、ボタンがモーダルビューでクリックすると

  1. を、その後、(退去)自体を閉じ@」 launchProject "オブジェクト:nil];

  2. DetailViewController意見が出てスイッチングされていない理由を分割ビューコントローラは、この通知のためのリスニング、およびSVC

 
-(void)launchProject:(NSNotification *)notification { 
    Project* secondDetail2 = [[Project alloc] initWithNibName:nil bundle:nil]; 
    ProjectRootController* secondRoot2 = [[ProjectRootController alloc] initWithNibName:nil bundle:nil ]; 
    self.splitViewController.viewControllers =[NSArray arrayWithObjects: secondRoot2, secondDetail2 , nil]; 

} 

でビューを切り替えているの内側に私は理解していません。これに関するアドバイスは大歓迎です。

答えて

0

あなたはすべてのコードを表示していないため、通知の仕組みを誤解していると思います。最初は混乱するかもしれませんが、それはとても簡単です。これまでのところ、あなたが持っている:

[[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil]

罰金です。

は、しかし、あなたはまた、init機能のように、どこか

[[NSNotificationCenter defaultCenter] 
addObserver:self 
selector:@selector(launchProject:) // selector should be your function name, launchProject 
name:@"launchProject" // notification name - must be same as what is given to postNotificatioName. 
object: nil]; 

を持っている必要があります。

つまり、postNotificationName:@"launchProject"は、関数launchProjectを呼び出しません。 NSNotificationCenter defaultCenterに「launchProject」という名前の通知を送信します。その特定の通知を探していない場合、何も起こりません。

希望することができます。

+0

非常に役に立ちます。御時間ありがとうございます。 – Aaron

+0

@Aaron、答えの左側にある緑色のチェックマークのアウトラインをクリックして回答を受け入れることができます。この回答と他の質問の回答を検討し、該当する場合は「受け入れ」チェックマークをクリックしてください。 – jball

関連する問題