0

I'm trying to have two different tableviews inside a scene but the only way to do this in storyboard is my using a view controller and if I use a tableview controller it doesn't let me drag a new tableview and so when I run it using the view controller it gives me the error: from storyboard "Main", but didn't get a UITableView.'

What can I do?

2 Answers2

0

you can set sections and set different table view cell per every section. also you can make custom table cell or xib table view cell to have different cells.

Masoud Roosta
  • 455
  • 9
  • 19
  • Thank you! What do you mean set sections? The thing is I dont want to make different cells I want to make different tableviews – Cristina Barclay Mar 03 '20 at 04:46
  • if you want to have two tableViews vertically, you can draw them with one TableViewController. you can set 2 sections for table so users see 2 different tableviews in one scene. but you should set appropriate design. although you can create it with ViewController easily. – maryam chaharsooghi Mar 03 '20 at 06:22
0

Do you want two tables that each scroll independently? (maybe side by side?) Or do you want to include two sets of data in a single table so that you have to scroll past one to see the other?

If you want to have just two different set of data show in the same table but separated, you can create two sections. This page has a really good overview: https://developer.apple.com/documentation/uikit/uitableview

You'll want to implement these methods in your UITableViewController:

var mydata = [["siamese", "tabby", "orange", "persian"], 
              ["wolfhound", "labrador", "german shepherd"]]
override func numberOfSections(in tableView: UITableView) -> Int {
    return mydata.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return mydata[section].count
}

Each of the methods that has a section variable should lookup the data for that section and return the right information.

If you want two tables that scroll independently of each other, you will need to create a UIViewController and have two models for the data and return the right one for the correct table. Create IBOutlet for each of the tables, and set the delegate and datasource for each with the right data.

This question asks about UIPicker with two data sources - you can do something very similar with your tables: https://stackoverflow.com/a/55527743/9878866

N.W
  • 672
  • 2
  • 8
  • 19