presentModalViewController does not want to work when called from a protocol method

Posted by johnbdh on Stack Overflow See other posts from Stack Overflow or by johnbdh
Published on 2010-05-21T19:24:18Z Indexed on 2010/05/22 5:20 UTC
Read the original article Hit count: 433

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...

  1. Restarted xCode and the simulator
  2. Ran on the device (iTouch)
  3. Presenting eventEditViewController instead of navigationController
  4. Using Push instead of presentModal.
  5. 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.
  6. 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

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode