I have a project with the following:
navigationController:
- usersViewController (UITableViewController) [rootViewController]
- photoViewController (UIViewController)
- chatViewController (UIViewController) (It has a tableView as a subview)
I'm also using the ZTWebSocket code to make a webSocket connection. I'm choosing to define & connect the webSocket in the appDelegate (making it the delegate for the webSocket). But, when I define the messageReceived callback of the webSocket class, I resort to some clever tactics to also insert the new message into the last row of the tableView that's a subview of the chatViewController.view. Here's how I go about accessing this tableView from the appDelegate.m file:
if ([navigationController.visibleViewController isKindOfClass:[ChatViewController class]]) {
ChatViewController *chatViewController = (ChatViewController *)navigationController.visibleViewController;
// insert row with received message in tableView of chatViewController
}
Is this the way to go about things? Or is there a better way to organize all this?
Also, I'm not using any nib files. Should I alloc/init all the view controllers in the appDelegate and then never again? Right now, I'm allocing everything in the viewControllers. But for the chatViewController, I think this causes it to lose it's scroll position everytime I navigate back to it. How do I fix this? When do I allocate viewControllers that are part of the navigationController? Also, the usersViewController has a modal view called profileViewController. Should I be initing the profileView in the appDelegate too?
Are there any good examples of how to organize code with a navigationController that has many viewControllers, while being able to access the viewControllers from different files, etc.
The code is at: http://github.com/acani/acani-chat/tree/master/Lovers2/
Thanks!
Matt