1

I have a view controller and a table view contoller. In my view controller, I have 6 different buttons which when pressed should each load different arrays table view.

I made this diagram:

How should I proceed?

2
  • You can have a table view section for every button and reload it (hide or show data) when necessary. Commented Mar 3, 2016 at 13:30
  • @Kevin This questions is too vague, asking how to solve a general problem is not recommended. You need to pinpoint an issue you are having, not ask how to code some general requirement. Commented Mar 3, 2016 at 21:02

1 Answer 1

2

The solutions to this can range from very simple to more involved depending on how different the contents and behaviours are between your 6 arrays.

Simplest: All six arrays have the same structure and behave exactly the same in the table view.

--> Define a "current" array variable for your table view data source and copy the content of the selected array to it when a button is pressed. Then call reloadData.

A little more complex: All six arrays have the same structure but must show different content in the table view.

--> Use "Current" array variable as above but define multiple prototype cells in the table view. Maintain an internal variable in your view controller to determine which button is currently selected. In the getCellForRowAtIndexPath method, use your internal variable in a switch statement to perform the appropriate dequeuing and mapping of cell contents.

Most complex: Arrays have different structures and must show different content/behaviour.

---> Define a class for each array and implement the datasource and delegate methods specific to the structure and cell content/behaviour that you need. In your buttons, switch the table view's delegate to the corresponding class. (this will help keep the specifics of each array type cleanly separated)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.