0

I'm making an application with xcode, and I have a trouble with passing data between views.
I want to set in detail view, a date of a calendar. Then when I go back to the master view I want to see the events in the selected date, but I don`t know how I make it.
Can you help me?

4

2 回答 2

1

这就是你如何在两个班级之间进行交流

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

就那么简单

还有另一种在两个类之间进行通信的方法是应用程序委托使您成为应用程序委托的对象,然后将您想要的应用程序委托的特定变量分配给您,然后您可以在项目中的任何地方使用该变量

像这样创建应用程序委托对象

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

基本上有两种最常见的方法:

1)如果您在项目中使用情节提要,请使用 unwind segue。该方法在这里得到了完美的讨论:

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 回答