Question

First of all I don't know C+, I only know HTML and CSS. I can only do a little bit like a WebView and so on. At the moment, I make an app with more than 80 ViewControllers and I currently link all of them together. It's a stupid work. 40 ViewController have the same layout but only the content is changing. And they all have 3 links. "Save, Go to next page and Back". The "next page" are there also 40 times. And they have all the same layout too. But only the links to Safari are changing.

Is there a simple way for me to have only a couple of ViewController and do the residual things with code?

It would be so nice. Thank you and a nice day.

https://i.stack.imgur.com/vCdo2.png

Image: Rectangle = Same layout only the content and the links are changed.

Was it helpful?

Solution

Wow. If you have 80 view controllers for a simple application, you know you're going wrong somewhere!

All you need is one view controller for displaying this content. You should detect when one of the buttons has been tapped, and then modify the UI to suit the action. You can store all the information per page in an NSMutableArray, and increment or decrement the index depending on whether the user tapped "Go to the next page" or "Back", respectively. Furthermore, if they click "Save", you can modify the NSDictionary at the current index of the array, and replace it in the array.

OTHER TIPS

Gack. A basic rule with computers: Any time you duplicate the same thing over and over, with only the content changing between instances, you are doing something wrong.

In this case, you should create a single view controller in your storyboard. Give it a unique storyboard identifier.

Create a custom subclass of UIViewController and set your view controller in IB to be an instance of that class. Customize it with the views and logic that you need.

When you need to invoke a new instance of your view controller, use the UIStoryboard method instantiateViewControllerWithIdentifier: That method will create a new, blank instance of your view controller class. You can then populate it with data and display it (either by using presentViewController:animated:completion:, or using pushViewController:animated: if you're using a navigation controller.

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