presentModalViewController does not want to work when called from a protocol method
- by johnbdh
I have a subview that when double tapped a protocol method on the subview's parent view controller is called like this...
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
if (theTouch.tapCount == 1) {
} else if (theTouch.tapCount == 2) {
if ([self.delegate respondsToSelector:@selector(editEvent:)]) {
[self.delegate editEvent:dictionary];
}
}
}
Here is the protocol method with the dictionary consuming code removed...
- (void)editEvent:(NSDictionary){
EventEditViewController *eventEditViewController =
[[EventEditViewController alloc]
initWithNibName:@"EventEditViewController" bundle:nil];
eventEditViewController.delegate = self;
navigationController = [[UINavigationController alloc]
initWithRootViewController:eventEditViewController];
[self presentModalViewController:navigationController animated:YES];
[eventEditViewController release];
}
The protocol method is called and runs without any errors but the modal view does not present itself.
I temporarily copied the protocol method's code to an IBAction method for one of the parent's view button's to isolate it from the subview. When I tap this button the modal view works fine.
Can anyone tell me what I am doing wrong? Why does it work when executed from a button on the parent view, and not from a protocol method called from a subview.
Here is what I have tried so far to work around the problem...
Restarted xCode and the simulator
Ran on the device (iTouch)
Presenting eventEditViewController instead of navigationController
Using Push instead of presentModal.
delaying the call to the protocol with performSelector directly to the protocol, to another method in the subview which calls the protocol method, from the protocol method to another method with the presentModal calls.
Using a timer.
I have it currently setup so that the protocol method calls a known working method that presents a different view. Before calling presentModalViewController it pops a UIAlertView which works every time, but the modal view refuses to display when called via the protocol method.
I'm stumped. Perhaps it has something to do with the fact that I am calling the protocol method from a UIView class instead of a UIViewController class. Maybe I need to create a UIViewController for the subView??
Thanks,
John