Reputation: 136
I have created the button in the viewdidload method:
UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 addTarget:self action:@selector(showVideo:)forControlEvents:UIControlEventTouchUpInside];
In button action method i called the segue programatically:
- (void) showVideo:(id)sender {
[self performSegueWithIdentifier: @"MySegue" sender: self];
}
In prepare for segue method the code to call the modal view controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"])
{
Xen_VideoViewController *addController = [segue destinationViewController];
[self presentViewController:addController animated:YES completion: nil];
}
}
i referred the link [link]:Creating a segue programmatically
but i am getting the error as
"Application tried to present modally an active controller"
i need to show the modal view controller when the button pressed but the button was created programatically. the button was repeated in the scroll view.
Any other method to get the modal view controller?
Thanks in advance….
Upvotes: 0
Views: 109
Reputation: 5462
You should not present
the addController
on your prepareForSegue
method.
I refer to the link you yourself shared:
https://stackoverflow.com/a/17012857/1939409
You should create the seque
in your xib
file and then when you call below line:
[self performSegueWithIdentifier: @"MySegue" sender: self];
the app will present the destination ViewController
based on your xib-created segue
. so this is not necessary to call presentViewController
in the prepareForSegue
method.
If you already created the segue in your xib
so just remove the prepareForSegue
method and every thing should be OK.
Also if you even, do not want to create the segue in your xib. So I think the only way is presenting modal view controller.
Upvotes: 1