Take the 2-minute tour ×

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.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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

    [delegate customMessage];
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer


