vedran
vedran

Reputation: 1153

iphone app with two UITableViewControllers side by side

I am attempting to build an iphone app with two tables, side-by-side, where both tables are always visible AND individually scrollable. Is this possible?

I have read a number of answers to similar questions on this site where people suggest using 'two UITableViewControllers, side by side'

Sounds like exactly what I need, but I can not find any examples.

My main question is: how do you actually get two UITableViewControllers on the same screen in IB?

Alternatively, is the correct way to do this by having two TableViews side-by-side within a single UITableViewController?

Any help would be much appreciated

Upvotes: 2

Views: 1041

Answers (3)

vedran
vedran

Reputation: 1153

Although I took initial guidance from @Aadhira's answer above, I thought I'd completely answer my question for anyone else who might find this useful (I got it to work by the way)

I created a storyboard with the following hierarchy of views/view controllers

UITableViewController Controller - UITableView ViewContainer -- UITableView Left -- UITableView Left

I created the table view 'ViewContainer' to 'contain' the two table views (Left and Right) which I wanted to draw. The reason I felt it was easier to do it this way is because there was no other way to resize the Left and Right table views in IB so that they only take up half of the screen widht. Whenever I I put them directly inside the table view controller Controller, they would take up the full widht (I guess I could have controlled their width programatically). Putting them inside the table view ViewContainer allowed me to resize them.

I made Controller the delegate and data source for Left and Right. Then, inside Controller, I had to make sure that I had some code to identify which table (Left or Right) is being drawn. ViewContainer is largely ignored and so far I am not using it

I added the following code to numberOfSectionsInTableView, numberOfRowsInSection and cellForRowAtIndexPath

 switch (tableView.tag) {
    case 100:   //the requesting object is the Left TableView
    {
        //perform functions specific to Left;         
    }
        break;
    case 200:   //the requesting object is the Right TableView
    {
        //perform functions specific to Right;         
    }
        break;    
    default:
        //error handling code
        break;
}

I set the tags for table views Left and Right to 100 and 200 respectively. This allowed me to populate Left and Right correctly (they contain different objects)

Upvotes: 1

k.shree
k.shree

Reputation: 119

Search for SplitView controller in iphone.You will get your answer

Upvotes: 0

Ilanchezhian
Ilanchezhian

Reputation: 17478

You can have two UITableViews in a single nib file ( and so it has only one view controller). But set 2 different classes (which conforms to UITableViewDataSource protocol) as datasource for the 2 tableviews.

Upvotes: 1

Related Questions