从UIView(.xib)加载UIViewController按钮操作
问题描述:
我在Interface Builder中创建了一个UIView。我有一个按钮。我可以通过点击UIView按钮加载应用程序中的任何ViewController?我的UIView不在导航控制器下。从UIView(.xib)加载UIViewController按钮操作
答
你可以这样做
YourViewController *aView = [[YourViewController alloc]
initWithNibName:@"xibName" bundle:nil];
[self presentViewController:aView animated:YES completion:nil];
答
您可以使用NSNotification以通知的ViewController呈现另一个视图控制器。
点击此处了解详情:
NSNotificationCenter Class Reference
显示的视图控制器具有:
ViewController *viewController = ...;
[self presentViewController:viewController animated:YES completion:NULL];
另一种选择是,从你的按钮调用委托。
我想从UIView.UIView加载UIViewController没有presentViewController方法。 – Sofeda 2014-08-28 11:45:10
比你可以这样做[yourViewObject addSubview:aView.view]; – Rajesh 2014-08-28 11:48:42
在这种情况下,只有UIViewController.view可见。我需要ViewController作为rootviewController – Sofeda 2014-08-28 11:50:14