Lewandowski
Lewandowski

Reputation: 3

Passing data from detail to master in ios6

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?

Upvotes: 0

Views: 601

Answers (2)

Prakash Desai
Prakash Desai

Reputation: 511

this is how you can communicate between 2 class

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

simple as that

there is another way to comunicate between 2 classes is that app delegate make object of you app delegate and then assing what you want to particular varible of app delegate and then you can use that variable anywhere in project

create app delegate object like this

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

if you are using storyboard then you can use prepareForSegue like below

   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:...]) {
        MyViewController *controller = (MyViewController *)segue.destinationViewController;
        controller.myProperty1 = ...;
        controller.myProperty2 = ...;
    }
}

Upvotes: 1

Yevhen Dubinin
Yevhen Dubinin

Reputation: 4733

There are basically two most common approaches:

1) use unwind segue if you're using storyboard in the project. The approach is perfectly discussed here:

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

2) use delegate pattern. I found the below tutorial quite useful when I had started to learn delegation:

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

Upvotes: 0

Related Questions