简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM