PDA

View Full Version : UIView calls method of its UIViewController?!




siliconKai
Dec 15, 2008, 04:26 AM
Hi guys,
is it possible that a UIView calls a method of its UIViewController?
Haven't found anything useful ...
Thanks for your help in advance.



jnic
Dec 15, 2008, 05:54 AM
Either extern the view controller or keep a pointer in the view which the view controller updates with a reference to itself.

siliconKai
Dec 15, 2008, 06:31 AM
thanks!
But what do you mean with "extern the view controller"?

siliconKai
Dec 15, 2008, 09:09 AM
how do i assign the pointer to the view controller?
i have subclassed UIView, added a pointer to my subclass of UIViewController.

now i want to assign the pointer assigned as in ViewDidLoad of UIViewController:
myView.viewControllerPtr = self;

if I call in myView [ viewController method ]; The method is not called. I have no compile errors or warnings.

What is going wrong?

dejo
Dec 15, 2008, 11:27 AM
is it possible that a UIView calls a method of its UIViewController?
Yes, and basically that is normally how things work. When you have a view-controller assigned as the delegate for a view, you are telling it that the view-controller will handle most methods calls for the view. That's the controller's whole purpose for being. For example, if you have a UIView that contains a UITextField, than your UIViewController will handle the textFieldShouldReturn: call (assuming you have properly setup your UIViewController as the delegate for the UIView and told it to implement the TextFieldDelegate protocol)

What method are you trying to call?

how do i assign the pointer to the view controller?
i have subclassed UIView, added a pointer to my subclass of UIViewController.

now i want to assign the pointer assigned as in ViewDidLoad of UIViewController:
myView.viewControllerPtr = self;

if I call in myView [ viewController method ]; The method is not called. I have no compile errors or warnings.

What is going wrong?
First, if you are setting:
myView.viewControllerPtr = self;
then you'll need to call methods via:
[viewControllerPtr method];
I'm sure that's what you meant to say, right? :)

I think some more details of what you have your UIView and UIViewController doing and what it is you're trying to accomplish will help us to answer your question better. That is, be more specific.

siliconKai
Dec 17, 2008, 06:48 AM
I have a ViewController with 2 Views. One View is invisible located above the displayed at position y=-480px. If the users taps on a button, the invisible display with a selection will be diplayed on screen. If the user selects something in the view the view will be hidden again and a viewcontroller method should be called!

It works similar to the UIImagePickerController with the PhotoLibrary as source.

siliconKai
Dec 17, 2008, 09:18 AM
okay. i got it. i have changed the TableViewDelegate from the View to the ViewController and now it works.

Thanks!