UIView calls method of its UIViewController?!

Discussion in 'iOS Programming' started by siliconKai, Dec 15, 2008.

  1. siliconKai macrumors newbie

    Sep 4, 2008
    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.
  2. jnic macrumors 6502a

    Oct 24, 2008
    Either extern the view controller or keep a pointer in the view which the view controller updates with a reference to itself.
  3. siliconKai thread starter macrumors newbie

    Sep 4, 2008
    But what do you mean with "extern the view controller"?
  4. siliconKai thread starter macrumors newbie

    Sep 4, 2008
    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?
  5. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    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?

    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.
  6. siliconKai thread starter macrumors newbie

    Sep 4, 2008
    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.
  7. siliconKai thread starter macrumors newbie

    Sep 4, 2008
    okay. i got it. i have changed the TableViewDelegate from the View to the ViewController and now it works.


Share This Page