3

I am working with the universal apps. Now i want to create a three table views in my view controller for iPAD. I have three separate view controllers with XIB.So how can i add the other two table view as subview in the main controllers. Please give me some sample applications and links. In my application, i have three view controllers and add a subview as table view(not UITableViewController). On clicks the first table view data, it navigates to the second table and clicks the second table view data, it navigates to the third table view.

 Hierarchy:

   MainViewController:
     --SubTableView1 
     --SubTableView2 

See the image below, alt text

Please Help me out.

Thanks!!

Pugalmuni
  • 9,350
  • 8
  • 56
  • 97

3 Answers3

11

I wrote an example with two TableViews on one view. In my code each TableView has it own controller, as I can avoid if else blocks in my delegate methods, as this would lead to high and unwanted coupling.
These codes are very rough, as I was a beginner, when I wrote it. i.e. I am not using properties in it.
The TableViews itself can be added to their super view via Interface Builder.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • Thanks, that's really helpful! It helped me locate the error in my code which was that I set the delegate and data source in the init method instead of in viewDidLoad. It will not work to set them in the init method. – Vanja Apr 03 '12 at 13:47
  • Fantastic project that I just downloaded to look at. Thank you very much! I'm left wondering if it's possible to have two table views with two datasources but a single controller. What do you think? ** EDIT: Looking at it now, it seems you have two controllers defined within the single view's controller. I like that much better than just adding disparate code into a single view for multiple views, nice implementation! – Danny Jan 15 '13 at 19:06
  • I dont see any problems with that – vikingosegundo Jan 15 '13 at 19:07
4

A table view is just a view you can use. It doesn't have to be bound 1:1 to a view controller, but if it's not, you need to set up the custom single view controller that owns the screen, and then get it to own all three table views as subviews. You need to be careful about which object is the delegate and data source of each views, and do the right thing with providing cells, etc. If the same controller is the delegate/data source of all the table views, you have to switch in the delegate methods to do the right thing on each.

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
1

I just completed a section of my App and I was able to make multiple tableviews in one ipad display.

But the credit goes to another StackOverflow problem resolution team. Reading this I was able to determine the real issue and that gave me the root of the answer. The root cause issue is related to managing the dataSource and delegate of the TableView with a separate controller... You will need to closely read the answer. I did, and my App now works well.

Here is the item: UITableView issue when using separate delegate/dataSource

Community
  • 1
  • 1
user589642
  • 396
  • 3
  • 5