0

xcode でアプリケーションを作成していますが、ビュー間のデータの受け渡しに問題があります。
詳細ビュー、カレンダーの日付を設定したい。その後、マスター ビューに戻ったときに、選択した日付のイベントを確認したいのですが、どうすればよいかわかりません。
手伝って頂けますか?

4

2 に答える 2

1

これは、2つのクラス間で通信する方法です

ViewController *dvController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
// ViewController is controler where you want to send date from particular controler we are making object of ViewController where you want to send data
    dvController.selectedBirthdate = selectedbirthdate;
    dvController.selectedName = selectedname;
    //you are sending data in above two lines just imagine you are sending string




  [self.navigationController pushViewController:dvController animated:YES];
  //then pushviewcontroller and there you go
  [dvController release];

そのような単純な

2つのクラス間で通信する別の方法は、アプリデリゲートがアプリデリゲートのオブジェクトを作成し、アプリデリゲートの特定の変数に必要なものを割り当てることです。その後、プロジェクトのどこでもその変数を使用できます

このようなアプリデリゲートオブジェクトを作成します

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
//and then access the variable by appDelegate.variable

ストーリーボードを使用している場合は、以下のように prepareForSegue を使用できます

   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:...]) {
        MyViewController *controller = (MyViewController *)segue.destinationViewController;
        controller.myProperty1 = ...;
        controller.myProperty2 = ...;
    }
}
于 2013-04-22T11:03:16.507 に答える
0

基本的に、最も一般的な 2 つのアプローチがあります。

1) プロジェクトでストーリーボードを使用している場合は、アンワインド セグエを使用します。アプローチはここで完全に議論されています:

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/CreatingAddView/CreatingAddView.html

2) デリゲート パターンを使用します。委任を学び始めたとき、以下のチュートリアルが非常に役立つことがわかりました。

http://www.roostersoftstudios.com/2011/04/12/simple-delegate-tutorial-for-ios-development/

于 2013-04-23T10:11:21.907 に答える