Pergunta

I'm making a basic app using a navigation controller and table views, and I realized that with storyboards it's possible to link 1 view controller to itself and use 2 types of dynamic cells, 1 that links back into the view and 1 that links out, and display one or the other depending on where in the navigation you are.

The way I've been doing it, there were 2 VCs, each with a table view inside, the first leading to the next.

My question is, which way should I go - 1 VC, or 1 for every level of navigation?

If you need, I can post screenshots of the storyboard or code. Any help is appreciated, and thanks in advance :)

Foi útil?

Solução

When using segue's with storyboards, they create new instances, so I guess you could link back to yourself, however I would not do that as it would be overly "clever". Rather, I'd advise to use separate view controllers for clear distinction of purpose and segue to them as needed.

It is ok to create a many to one type model where you segue many times to a single scene. I do this for things like a modal help page. For example, I've provided a "help" button on multiple pages and each of them segue's to the same "HelpViewController". That controller is a standard view, but the text changes, so based on each segue, a different help text is set but otherwise the view looks the same. On the storyboard it looks a bit odd with 4 or 5 segue lines going into it, but it works very nicely for that use case.

So, in closing, try to isolate unique path's and don't be too clever when setting them up even if it takes more scenes - you'll future self will thank you. And, reuse common views where it makes sense, the same as you would in code.

hope that helps best wishes

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top