f_qi
f_qi

Reputation: 699

UITableview show different data based on cell selected

In the app I'm designing, here is what I'm trying to achieve:

  1. A main view, which only have 3 items, "to-do", "shopping list", "note".

  2. A detail view, based on the item selected in the main view, display different set of data. This is a UITableView.

  3. The transition from the main view to detail view is using segue, more like the main view is a front view, once an item is selected, a segue is called to transit to the detail UITableView.

My questions are:

  1. For the main view, should I use UITableView with only 3 cells and disable scrolling? or should I use a UIView with 3 buttons?
  2. How can I display different set of data in the detail view, based on the selection in the main view? eg. if the user selected "todo", then the detail view should display a to-do list; if the use selected "shopping list", then display the data from shopping list.

An example or a link is much appreciated.

UPDATE:
I plan to use NSUserDefault for storing the data, since to-do list and shopping list are relatively very light weight. In the future, if needed, I'll consider using firebase or iCloudfor backup and syncing purpose.

Upvotes: 1

Views: 148

Answers (3)

f_qi
f_qi

Reputation: 699

Here is a solution I found that solves my question.

Upvotes: 0

Taylor M
Taylor M

Reputation: 1865

Question 1: As Gabe said, you could do either, but it's probably simpiler to just use three buttons.

Question 2: The best way to handle view controllers displaying different data is to have different view controllers. Use one view controller for each category you have. Use a navigation controller to create the transitions between view controllers. From the buttons to the detail views, create show segues. Consider a storyboard set up like this:

Upvotes: 1

Gabe Spound
Gabe Spound

Reputation: 590

Question 1: You could do either, but it would be easier to just make a UIView with 3 buttons.
Question 2: The best way to accomplish this is with the present segue. Make 3 UITableViewController to be your detail views for the 3 buttons in the main view. Then drag from each button to its respective tableViewController and select present. Give each segue an identity. Then, in your main view, in prepareForSegue, make three if statements checking for if the segue.identifier == "buttonSegueIdentifier". In each if statements, perform the necessary tasks. Finally, when each button is clicked, call prepareForSegue.

Upvotes: 1

Related Questions