简体   繁体   English

从UIView(.xib)按钮加载UIViewController

[英]Load UIViewController from UIView(.xib) Button Action

I have created a UIView in Interface Builder.I have a button in it.Can i load any ViewController in the app by tapping the Button of UIView ? 我已经在Interface Builder中创建了一个UIView。我有一个按钮。我可以通过点击UIView的Button来加载应用程序中的任何ViewController吗? My UIView is not under Navigation Controller. 我的UIView不在导航控制器下。

You can do like this 你可以这样

YourViewController *aView = [[YourViewController alloc]
                              initWithNibName:@"xibName" bundle:nil];
[self presentViewController:aView animated:YES completion:nil];

you could use a NSNotification to inform a ViewController for presenting another ViewController. 您可以使用NSNotification通知Vi​​ewController呈现另一个ViewController。

More information here: 此处的更多信息:

NSNotificationCenter Class Reference NSNotificationCenter类参考

Show the ViewController with: 显示ViewController:

ViewController *viewController = ...;

[self presentViewController:viewController animated:YES completion:NULL];

Another option is, calling delegate from your button. 另一种选择是从您的按钮调用委托。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM