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

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
I created a nib in the Interface Builder with a sub view that I will use for loading dynamic content. The subview is wired to an IBOutlet and when a certain event occurs I went to load a specific control into that sub view. I tried instantiating the view I was going to use and then adding it as a subview of the the contentView IBOutlet, but all I get is an exception.

Code:
- (IBAction)sellItem {
    if(sellView == nil) {
		SellViewController *viewController = [[SellViewController alloc] initWithNibName:@"SellViewController" bundle:[NSBundle mainBundle]];
		self.sellView = viewController;		
		[viewController release];
	}
	
	[self.sellView setItem:item];
	[self.contentView addSubview:self.sellView];
}

My application crashes on that last line. (Which also happens to be producing a "warning: passing argument 1 of 'addSubview:' from distinct Objective-C type.". I tried casting it to a (UIView *) but that still gives me exceptions.

Exception:
2008-11-06 23:28:34.580 iPhoneHelloWorld[4069:20b] *** -[SellViewController superview]: unrecognized selector sent to instance 0x479480
2008-11-06 23:28:34.582 iPhoneHelloWorld[4069:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[SellViewController superview]: unrecognized selector sent to instance 0x479480'
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Heed the compiler warning, it's trying to tell you that you're attempting to cast a view controller to a view (sellView is a SellViewController). I think what you meant to do was:

Code:
[self.contentView addSubview:self.sellView[B].view[/B]];
 

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
Heed the compiler warning, it's trying to tell you that you're attempting to cast a view controller to a view (sellView is a SellViewController). I think what you meant to do was:

Code:
[self.contentView addSubview:self.sellView[B].view[/B]];

Well that is good to know. I will give that a shot, thank you. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.