Reputation: 595
I would like to know how to correctly show a view programmatically. I will try to explain what i did so far:
The application has a storyboard with two view controllers. One of them has an identifier: " detailview". When i click on a button on the initial view controller i want to show the view controller with the identifier "detailview". Currently i'm using this code:
TI4ViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"detailview"];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window addSubview:vc.view];
This works fine to show the view "detailview". But when i add a button on the detailview controller and add a touchdown event in the TI4ViewController(the view controller that's connected to "detailview") i'm getting an exception while clicking on this button.
I'm getting the following exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType TestDown:]: unrecognized selector sent to instance 0x6e0f670'
I'm using Xcode Version 4.3.2 (4E2002)
I'm not sure what i'm doing wrong here. I think the ViewController is released, but i'm not sure.
Upvotes: 0
Views: 135
Reputation: 595
Problem solved. I should have added the TI4ViewController as property of the initial view controller. Now it's removed from memory when you leave the function.
Upvotes: 0