Reputation: 1061
This is a noob question.what i want is to pass data from my QuizViewcontroller to QuizModalViewController.i was successful in creating a normal modal view controller but having problem when passing data between the two..below is my code.
QuizViewController
-(IBAction)button3Clicked:(id)sender
{
QuizModalViewController *mvid=[[QuizModalViewController alloc]initWithNibName:@"QuizModalViewController" bundle:nil];
mvid.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mvid animated:YES];
}
QuizModalViewController
- (IBAction)goBackToView
{
[self dismissModalViewControllerAnimated:YES];
//[controller loadQuestion:currentQuestionIndex+1];
}
Upvotes: 1
Views: 7167
Reputation: 359
You can also use the -(void)prepareForSegue:... - Method to share data between controllers.
For Example:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"Your_Identifier"]) {
TestViewController *controller = [segue destinationViewController];
NSArray *array = [[NSArray alloc] initWithObjects:@"",nil];
controller.objectInTestViewController = array;
}
}
Hope this helps someone....
Upvotes: 2
Reputation: 10045
-(IBAction)button3Clicked:(id)sender
{
QuizModalViewController *mvid=[[QuizModalViewController alloc]initWithNibName:@"QuizModalViewController" bundle:nil];
mvid.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
mvid.theDataYouWantToPass = theData; // this is how you do it
[self presentModalViewController:mvid animated:YES];
}
Note that theDataYouWantToPass
must be a property declared in the QuizModalViewController.h
file.
Upvotes: 4
Reputation: 33068
Make your QuizModalViewController
available at class scope instead of using a local variable.
Then in the goBackToView:
you can access the controller's content prior to dismissing it.
By the way: in your code you're leaking mvid
. Release it after presenting it modally.
Upvotes: 0