How to prevent a repetition of making new VC's

Discussion in 'iOS Programming' started by skobuv, Dec 10, 2016.

  1. skobuv macrumors newbie

    Dec 10, 2016
    Hi, I have a feature in app, where I have a list of items through tableView(1), when clicked on item, it redirects me to a new VC(2) (contains imageView, TextField, button). A button on the new VC redirects to a new VC containing a new list of items (to-do list for particular item).

    Because im going to have multiple items on the first list tableView(1) (up to 300) with different attachements (different image, text, button redirecting to unique to-do list), is it possible to use some function/switch from VC(2) , so I dont have to make new viewControllers over and over again ? Thank you for replies
  2. Dookieman macrumors 6502

    Oct 12, 2009
    Are you creating a new ViewController for each tableView row that you click on? You should be reusing the same "Detail Controller" (VC2) for each row you have in the tableView. You should never ever build a new VC for each tableView row, that would take forever and a View Controller shouldn't hold any data specific for itself, it should only be in charge of displaying data it recieves.

    You should pass the model/data you have to VC2 (detail controller) and have it populate the controller from the data you passed. That way you create the viewController one time and it can be reused.
  3. skobuv thread starter macrumors newbie

    Dec 10, 2016
    Thank you for your reply. Yes, I was about to make a new VC for each tableView row, but I thought there should be much easier and quicker way, just didnt know what to look for.

    Thank you again :)
  4. bjet767 macrumors 6502a

    Oct 2, 2010
    There's no requirement to have a single VC that covers all needs, but the template version is a master list that calls a single VC. It sounds like you will have a very complicated VC if each of the 300 items on the list have different needs for displaying their data.

    Is the 300 item list a data model of some sort, meaning does it point to a record with the data that will be displayed?
  5. skobuv thread starter macrumors newbie

    Dec 10, 2016
    Basically, I want to make a list of excercises , each item is a different excercise, leading to a new VC. That new VC contains different image and text, and button, which navigates to a new tableView VC (sort of calendar with times when the user used that excercise).

    I tried to search the internet to find a similar function, MVC model to figure it out, but haven't really found one.
  6. bjet767, Dec 17, 2016
    Last edited: Dec 17, 2016

    bjet767 macrumors 6502a

    Oct 2, 2010
    A table view is commonly used for navigating to new views that use a VC. However if the tableview is dynamically filled from a database it would be better to use a single VC as in the template provided by Xcode.

    What I would do is have a view that had items which would be hidden unless needed, but there comes a point where that gets out of control.

    The hardest part about programming is building a visual interface that is appealing to the user so keep it simple.

    As far as the tableview which has previous workouts, again I assume you will be saving them to some sort of file/database which is in the template model given in Xcode. Now if you want a calendar view of some sort I would save them to iCal.


    The more I read you idea it's not really difficult, but you will need to work on the file system/database because everything is based around it.

    You need a table of exercises with descriptions and images. Then there will be a relationship to some sort of table for the user that saves the dates and workout they did on that day. Your button will do a search of the table and build a list which is displayed in a tableview of the dates the workout was done.

    The heart of your app will be the tables.
  7. skobuv thread starter macrumors newbie

    Dec 10, 2016
    Making the feature with the date is not a problem, I have already came up with the structure, similar to To-do list with core data (with tableView).

    But the issue is, how to set up a relationship of items in the list of exercises with images and textFields of appropriate VC's , and items in the list of exercises with appropriate tableViews of the dates of the workouts.
  8. bjet767 macrumors 6502a

    Oct 2, 2010
    Do you know how to use Coredata or SQL, because both are supported by xCode and iOS. You will need to build a simple relational database to store the images and exercise information.

    If the number records is small just use a UIDocument and a custom NSObject with your exercises and images for storage.

    The VC is really not an issue unless you have a huge number of fields and image views to display.

    So you click on the exercise from the table.
    That row calls a function/method which filters the user's save workouts to an array.
    Then you display another tableview with the info from the array sorted in date order.
    Finally after the user selects the date row they want to view it displays a VC which is passed the data from the record selected and displays it in the associated view.

    So the flow is:

    Tableview of exercises -> select exercise (row) -> new tableview of dates exercise was performed -> select date (row) -> VC with data from that date.

    My first UITableview would not be linked to a master/detail, but the second would.

    That's the best I can help you, have fun!
  9. skobuv thread starter macrumors newbie

    Dec 10, 2016

Share This Page