Question

I am creating a simple app that let's the user view movies after clicking buttons. The first screen you see is the Main Menu with 2 buttons. One of them sends the user to a sub view which I coded as this in an IBAction method:

ViewConroller *nextView = [[ViewController alloc] initWithNibName:@"NextMenu" bundle nil];
[self.view addSubview:[nextView view]];
[nextView release];

This part is fine except that the sub view shows a 20 px bar across the bottom of the previous view. I looked around and none of the solutions like this one work for me. This isn't even the main problem. On the sub view, whenever I click a button, the app explodes. The IBAction methods break before even executing a line inside the method. Here, in the goBack IBAction method, I am trying to dismiss the subview and go back to the main menu:

[self.view removeFromSuperview];

My connections are correct in my XIB files and everything seems to be in order. The buttons just aren't executing. I'm not sure if it has to do with adding the sub view or what. I have done a lot of searching around on google and this website, but I still can't find a solution.

Here is an example of the error I'm getting:

Terminating app due to uncaught exception 'NSInvalidArgumentException, reason: '-[__NSCFType goBack:]: unrecognized selector sent to instance 0x5640b70'

Hopefully you guys can help me out, this is really quite frustrating. I feel like I've tried everything. Thanks for your time. Let me know if I need to provide any more information. Thanks again.

Was it helpful?

Solution

ViewConroller *nextView = [[ViewController alloc] initWithNibName:@"NextMenu" bundle nil];

View controller is created.

[self.view addSubview:[nextView view]];

self.view added value of nextView.view as it's subview and retained it (N.B. it retained next.view value not nextView itself)

[nextView release];

nextView is released and immediately deallocated (because it has never been retained by anybody)

Button is trying to send a message to deallocated object -> behavior is undefined, in your case some other object (or something that looks like an object) is there and it doesn't understand what goBack: means.

That's why you should not invent a wheel (especially if you are new to this) with your own navigation. Use UINavigationController instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top