newbie needs help with error involving insertSubview

Discussion in 'iOS Programming' started by tjh21cen, Jan 7, 2009.

  1. tjh21cen macrumors newbie

    Jan 6, 2009
    Hi Im really new at iphone development, just trying to get a basic program with some view controllers going. Im having an issue with an error:

    - (void)viewDidLoad {
    IntroViewController *introController = [[IntroViewController alloc]
    initWithNibName:mad:"IntroView" bundle:nil];
    self.introViewController = introController;
    [self.view insertSubview:introController.view];
    error shows up here as follows:
    warning: 'UIView' may not respond to '-insertSubview:'

    [introController release];

    I am simply trying to add my view with a loaded nib to the main view. Is view did load the best place for this? Any help, tips, etc are greatly appreciated. I can post more code if the problem cant be discovered with just this code.

    Also, how do you add code like I have seen in this forum? Thanks everybody
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Check the class reference for UIView. insertSubview: requires another parameter. That is, you must use insertSubview:aboveSubview:, insertSubview:atIndex:, or insertSubview:belowSubview. You could also look into using addSubview: and see if that suits your needs instead.

    Use the [ CODE ] / [ /CODE ] tags. See the [​IMG] icon in the toolbar.
  3. beachdog macrumors member

    Aug 10, 2008
    What he said. I do a lot of view manipulation in viewDidLoad and I just find it quite simple to use addSubView:.

    Also, your example looks a bit strange to me. You are in the 'ViewDidLoad' of one view controller, where you then load another viewcontroller from a nib file and then manipulate that second viewcontrollers view. I would have expected that if you wanted to manipulate that second view that you would have just put the code in the 'ViewDidLoad' method of that second view controller and just do


Share This Page