[英]How to Open a UIViewController on Click of UIButton In UIView
I wants to open a UIViewController on Click of UIButton which is inside a UIView .我想在单击UIView内的 UIButton 时打开一个 UIViewController 。 The UIView has it's own .h & .m file & The action property of button is declared inside the it. UIView有它自己的.h & .m文件 & 按钮的 action 属性在其中声明。
the navigation code is working fine if I am calling it from UIViewController of UIbutton which is like如果我从 UIbutton 的 UIViewController 调用它,导航代码工作正常,就像
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FilterDemoTableViewController *viewController = (FilterDemoTableViewController*) [mainStoryboard instantiateViewControllerWithIdentifier: @"FilterDemoTableViewController_Id"];
[[self navigationController]pushViewController:viewController animated:YES];
but if same code is calling from UIView .m file then it's not working plz help me.但是如果从 UIView .m 文件调用相同的代码,那么它不起作用请帮助我。
And it won't.它不会。 You can't call [self navigationController]
inside UIView
because it doesn't have one.你不能在UIView
调用[self navigationController]
因为它没有。
All you have to do is to reference the ViewController that owns your UIView
and call a method there.你所要做的就是引用拥有你的UIView
的 ViewController 并在那里调用一个方法。
Typically, you can do it with NSNotification
- not the best way but definitely works.通常,您可以使用NSNotification
来做到这一点——这不是最好的方法,但绝对有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.