我有:
UIViewController
A UIView
B:我在UIView
A UIViewController
的子视图
UIViewController
C 我做的是:
在UIViewController
A的viewDidLoad's
方法中,我称之为:
UIView *subviewB = [[Subview alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[subviewB subviewBMethod]; //
[self.view addSubview:subviewB];
SubviewBMethod代码是创建一个视图,在这个视图里面有一个按钮。单击此按钮后,它将更改为UIViewController
C。
我试过了:
[self presentModalViewController:self.UIViewControllerC animated:YES];
我收到此错误消息:
警告:不兼容的Objective-C类型'struct UIViewControllerC *', 传递参数1时预期'struct UIViewController *' 'presentModalViewController:animated:'来自不同的Objective-C类型
当我运行应用程序时,它在我单击按钮时立即终止,我打开了控制台错误,没有任何错误消息。我的方法一定是错的,因此我的问题是:
是否可以从另一个UIVIewcontroller
的{{1}}加载UIView
?如果:
答案 0 :(得分:1)
看起来你有这样的声明:
UIViewControllerC *UIViewControllerC;
^
何时需要:
UIViewController *UIViewControllerC;
答案 1 :(得分:1)
我最近做了同样的事情。 - 我有一个viewControllerA,它有一个seeMoreView(一个自定义视图)。当用户点击“查看更多”时,会显示viewControllerB。
我解决了这个问题:我将seeMoreView子类化。
我在seeMoreView中声明了一个委托 - 在这个答案中的语法: Delegates Vs. Notifications in iPhoneOS
在viewControllerA中,我在创建视图时将seeMoreView的委托设置为self。
在viewControllerA中,我实现了委托方法,该方法提供了viewControllerB。
(我不认为在MVC范例中从视图中调用视图控制器是一种很好的做法。)
答案 2 :(得分:0)
你能试试吗?
[self presentModalViewController:(UIViewController *)self.UIViewControllerC animated:YES];