0
votes

so I am building a simple chat app. I will have a login screen, register and later on a UITableViewController so show the friend list. I'm not sure if I should use a UINavigationController for this or just stick to UIViewControllers. Below are two images for the potential setups.: enter image description here

and: enter image description here

I'm just wondering is it generally better practice to use a navigation controller? I am also a little confused about what happens to a view controller when it is popped. Does [self.navigationController popViewControllerAnimated:YES]; keep the view controller in the memory to be accessed again later or is a new one created each time? The same question for [self dismissViewControllerAnimated:YES completion:nil], is this destroying the controller or storing it for use later? Thanks

3
I pretty sure that in both cases the view controller gets destroyed, and a new one is created. It's easy to check. Just override the dealloc method of the view controller and put an NSLog(@"destroyed"); in it.user3386109

3 Answers

1
votes

I'll give you my opinion about when to use a navigation controller.

If your app need to present its content in a hierarchical fashion (Master/detail) is pretty common to use a UINavigationController.

If you need to present some content that is not strictly related with the presenting content you can present it using a new view controller on top of it.

Regarding the memory, as soon as you don't keep any reference to the controllers either presented or pushed once remove (popped / dismissed) you loose any reference to them so no space used in memory

0
votes

I think you will stick to the UINavigationViewController. Simply because the login and registration are belonged to your user management. From the UX standpoints, it's better to use Modal if the scene you are going to present is somehow irrelevant to the current scene. Therefore, go with UINavigationViewController for your situation.

The second question is related to memory management. It's kind of like the reference counting. If you have something to reference the UIViewController, its reference counting won't drop to zero which mean the system won't clean this up. So, you still have way to get then. If you just simply pop then up or dismiss it without referencing it. The reference counting will become zero and the system will clean it.

0
votes

Note: If you want to simply display a view controller which doesn't need hierarchical navigation or a navigation bar then you wouldn't need to use a UINavigationController.

But in this case I would still suggest to use UINavigationController for the simple fact that your use case (Login Flow) can be completely addressed using a navigation flow.

In terms of memory there is now difference. Feel free to use any of them in this concern. Although how these views are presented has difference.