surendher
surendher

Reputation: 1378

How to implement a tableview inside a tableview?

I need to show a tableview within a cell of a tableView. I have a separate dictionary for tableview that is residing inside each cell of tableView. Where i need to assign the dictionary values to the tableview that is inside the cell

Upvotes: 0

Views: 83

Answers (1)

Joride
Joride

Reputation: 3763

Add the tableView as a subview to the cell. Next assign a delegate/datasource to the tableview. This can be the same object as the outer tableViews datasource/delegate. Every time a delegate method is called, the tableView is send along as a parameter and you can simply do (assuming you have properties for both tableViews):

if (tableView == self.outerTableView){
    // ... do stuff for outer tableView
} else if (tableView == self.innerTableView) {
    // ... do stuff for inner tableVIew
}

I am assuming here that you have only one cell with one tableView in it. If you have more cells with a tableView in it, the idea can stay the same, except that with many cells with tableViews there is surely a better place to handle the tableViewCallbacks than in the viewController of the outer tableView.

Upvotes: 1

Related Questions