从UIView将UIViewController推送到UINavigationController吗? [英] Push a UIViewController onto UINavigationController from a UIView?

查看:54
本文介绍了从UIView将UIViewController推送到UINavigationController吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我的事件处理发生在UIViewController中,因此我使用了以下代码行: [self.navigationController pushViewController:viewController animation:YES];

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

但是,现在我的事件处理程序在UIView中.具体来说,我正在使用-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

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

因此,从我的touchesEnded委托内部,如何将UIViewController推送到来自UIView的UINavigationController,它是提到的UIViewController的子视图.

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.

推荐答案

您可以在视图上创建一个委托,以便可以引用该视图的viewController.可以这样完成:

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;

然后在您的View控制器中,只需像这样设置视图的委托:

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];
}

这篇关于从UIView将UIViewController推送到UINavigationController吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆