tags:

views:

947

answers:

2

Typically, my event handling occurs in the UIViewController, so i used the following line of code: [self.navigationController pushViewController:viewController animated:YES];

However, now my event handler is in the UIView. specifically, i'm using - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event

So from inside my touchesEnded delegate, how do i push a UIViewController onto a UINavigationController from a UIView that is a subview of the UIViewController mentioned.

A: 

You need to add a reference to your UIViewController to your UIView. Then in the event handler, send a message to the UIViewController that will push the other controller. You could also do the push in the event handler, but the other way is more 'correct' in a MVC architecture.

Marco Mustapic
+1  A: 

You can make a delegate on your view so that you can refer back to the view's viewController. This could be done like this:

@interface MyCustomView : UIView
{ 
    id delegate;
}

@property(nonatomic, assign) id delegate;

Then in your View controller, you will simply set the view's delegate like this:

[myCustomView setDelegate:self];

Which will allow you to send messages to your delegate from within your custom view

-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
    [delegate customMessage];
}
Reed Olsen