Issit possible to load a UIVIewcontroller from uiview of another UIViewController
I have:
- an
UIViewController
A UIView
B: I added subview which is aUIView
to theUIViewController
A- an
UIViewController
C
What I did is:
in UIViewController
A's viewDidLoad's
method, I call this:
UIView *subviewB = [[Subview alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[subviewB subviewBMethod]; //
[self.view addSubview:subviewB];
SubviewBMethod code is to create an view, inside this view have a button. Once this button is clicked, it will change to UIViewController
C.
I tried this:
[self presentModalViewController:self.UIViewControllerC animated:YES];
And I got this error message:
warning: incompatible Objective-C types 'struct UIViewControllerC *', expected 'struct UIViewController *' when passing argument 1 of 'presentModalViewController:animated:' from distinct Obj开发者_如何转开发ective-C type
When I run the app, it terminates immediately when I click the button, I opened the console bug, there is no any error message. My method must be wrong, thus my question is:
Is it possible to load a UIVIewcontroller
from UIView
of another UIViewController
? If:
- Yes: How to do it?
- No: What should I do?
It looks like you have a declaration like this:
UIViewControllerC *UIViewControllerC;
^
When you want:
UIViewController *UIViewControllerC;
I've recently done the same thing. - I have a viewControllerA that has a seeMoreView (a custom view) on it. When the user clicks "see more", viewControllerB is presented.
I solved it like this:
I subclassed seeMoreView.
I declared a delegate in the seeMoreView - syntax in this answer: Delegates Vs. Notifications in iPhoneOS
In viewControllerA I set the delegate of the seeMoreView as self when creating the view.
In viewControllerA I implement the delegate method, which presents viewControllerB.
(I don't think it's good practice in the MVC paradigm to call a view controller from a view.)
Can you try this?
[self presentModalViewController:(UIViewController *)self.UIViewControllerC animated:YES];
精彩评论