View Full Version : newbie needs help with error involving insertSubview

Jan 7, 2009, 01:36 PM
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:@"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

Jan 7, 2009, 02:44 PM
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.

Also, how do you add code like I have seen in this forum? Thanks everybody
Use the [ CODE ] / [ /CODE ] tags. See the http://images.macrumors.com/vb/images/editor/code.gif icon in the toolbar.

Jan 7, 2009, 03:19 PM
You could also look into using addSubview:

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

[self.view addSubview:myView];