Drill down hierarchical data with UITableView

前端 未结 2 365
萌比男神i
萌比男神i 2020-12-08 23:53

I want to build an app to navigate a data hierarchy. The structure of this hierarchy is something like the one I\'m showing in the following image. A branch of the structure

2条回答
  •  囚心锁ツ
    2020-12-09 00:20

    Sure, you can re-use a UITableView. The UITableView has 2 fundamental pieces, the UITableViewDelegate and the UITableViewDataSource.

    UITableViewDelegate controls a lot of the table interaction and some display characteristics (heightForRowAtIndexPath and such). What happens when you select a row. Can you even select a row?

    UITableViewDataSource is the well, source of the data. How many sections does the table have? How many rows in each section? What are the content of the cell at Section X, row Y?

    You could for instance, use the same UITableView and UITableViewDelegate for each table in your hierarchy, but change the UITableViewDataSource. When you want to change the data source, you might do something like...

    if (isSingingBand) {
        self.tableview.dataSource = [TableABBADataSource alloc] init];
    } else {
        self.tableview.dataSource = [TableAABDataSource alloc] init];
    }
    [self.tableview reloadData];
    

    Apple's programming guide on Table Views should answer a lot of questions you might run into how implementation.

提交回复
热议问题