Hello
Following my last post, I have been trying to learn how to transition between views without using storyboard. I have been successful with the following two practice projects - this a breakdown of the structure:
1. Multiple views without a navigation controller
- CustomViewController1 created in AppDelegate
- CustomViewController1's view contains a toolbar with 2 buttons on it
- CustomViewControllers 2 and 3 created as IBOutlets in .xib file of CustomerViewController1
- insertSubView and removeFromSuperView methods used in ViewController1's .m file to load and unload CustomerViewControllers 2 and 3's views (by linking the toolbar buttons to actions)
This works fine.
2. NavigationController app
- NavigationController created in AppDelegate
- CustomTableViewController created in AppDelegate, passed to NavigationController using initWithRootViewController method, and then displayed using addSubView method.
- CustomTableViewController .xib contains a tableview and a CustomViewController as the detail view, which is linked to the CustomTableViewController via IBOutlet
Everything loads fine, and when didSelectRowAtIndexPath method is activated, I use pushViewController method with the CustomViewController property to load the detail view and it works fine.
So, my problem arose when I tried to mix the two together. I wanted to have a main menu screen with a button that, when pressed, would launch a navigation controller. Essentially, example 1 above for the menu and example 2 thereafter.
I have done the following:
- CustomViewController1 is loaded in AppDelegate and has just a completely empty view
- CustomViewController1's .xib file contains a MenuViewController linked via IBOutlet. MenuViewController is loaded by [self. view addSubView] method
- MenuViewController's view has a button on it. A navigation controller is declared within MenuViewController and, when the button is pressed, a CustomTableViewController as in example 2 is created, given to the navigation controller via initWithRootViewController, and then the rest is as example 2.
At this point, MenuViewController's view is a sub view of CustomViewController's view, the navigation controller's view is a sub view of MenuViewController's view and CustomTableViewController's view is the root view of the navigation controller.
I get "unrecognized selector sent to instance" errors on the pressing of the button.
When I moved the navigation controller stuff into CustomViewController1 instead, I got the same error for the cellForRowAtIndexPath method on scrolling the table view.
The cellForRowAtIndexPath method seems to get called when the CustomTableViewController is first created, but then it crashes when it is called again when I scroll some of the cells off the top of the screen.
Lastly, when clicking on a table view cell, the detail view doesn't load - the cell just highlights and nothing happens.
From trawling the internet most of this afternoon, I think it is maybe a problem with things getting released when they shouldn't be and so are not there to deal with some of the method calls.
If anyone can explain what is happening or, if what I am doing is totally wrong, explain simply the correct way for transitioning between different views that have their own view controllers then I'd be grateful.
Thank you and sorry for writing so much but I don't know which part is the problem.
Following my last post, I have been trying to learn how to transition between views without using storyboard. I have been successful with the following two practice projects - this a breakdown of the structure:
1. Multiple views without a navigation controller
- CustomViewController1 created in AppDelegate
- CustomViewController1's view contains a toolbar with 2 buttons on it
- CustomViewControllers 2 and 3 created as IBOutlets in .xib file of CustomerViewController1
- insertSubView and removeFromSuperView methods used in ViewController1's .m file to load and unload CustomerViewControllers 2 and 3's views (by linking the toolbar buttons to actions)
This works fine.
2. NavigationController app
- NavigationController created in AppDelegate
- CustomTableViewController created in AppDelegate, passed to NavigationController using initWithRootViewController method, and then displayed using addSubView method.
- CustomTableViewController .xib contains a tableview and a CustomViewController as the detail view, which is linked to the CustomTableViewController via IBOutlet
Everything loads fine, and when didSelectRowAtIndexPath method is activated, I use pushViewController method with the CustomViewController property to load the detail view and it works fine.
So, my problem arose when I tried to mix the two together. I wanted to have a main menu screen with a button that, when pressed, would launch a navigation controller. Essentially, example 1 above for the menu and example 2 thereafter.
I have done the following:
- CustomViewController1 is loaded in AppDelegate and has just a completely empty view
- CustomViewController1's .xib file contains a MenuViewController linked via IBOutlet. MenuViewController is loaded by [self. view addSubView] method
- MenuViewController's view has a button on it. A navigation controller is declared within MenuViewController and, when the button is pressed, a CustomTableViewController as in example 2 is created, given to the navigation controller via initWithRootViewController, and then the rest is as example 2.
At this point, MenuViewController's view is a sub view of CustomViewController's view, the navigation controller's view is a sub view of MenuViewController's view and CustomTableViewController's view is the root view of the navigation controller.
I get "unrecognized selector sent to instance" errors on the pressing of the button.
When I moved the navigation controller stuff into CustomViewController1 instead, I got the same error for the cellForRowAtIndexPath method on scrolling the table view.
The cellForRowAtIndexPath method seems to get called when the CustomTableViewController is first created, but then it crashes when it is called again when I scroll some of the cells off the top of the screen.
Lastly, when clicking on a table view cell, the detail view doesn't load - the cell just highlights and nothing happens.
From trawling the internet most of this afternoon, I think it is maybe a problem with things getting released when they shouldn't be and so are not there to deal with some of the method calls.
If anyone can explain what is happening or, if what I am doing is totally wrong, explain simply the correct way for transitioning between different views that have their own view controllers then I'd be grateful.
Thank you and sorry for writing so much but I don't know which part is the problem.