Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

siliconKai

macrumors newbie
Original poster
Sep 4, 2008
14
0
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

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Either extern the view controller or keep a pointer in the view which the view controller updates with a reference to itself.
 

siliconKai

macrumors newbie
Original poster
Sep 4, 2008
14
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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:
Code:
myView.viewControllerPtr = self;
then you'll need to call methods via:
Code:
[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

macrumors newbie
Original poster
Sep 4, 2008
14
0
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

macrumors newbie
Original poster
Sep 4, 2008
14
0
okay. i got it. i have changed the TableViewDelegate from the View to the ViewController and now it works.

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.