IOS OC UITableView
object c 中的UITableView 可以实现灵活的列表内容效果。列表的内容可以是多种类型元素。
主要步骤
- 正确实现numberOfSectionsInTableView和numberOfRowsInSection,获取正确的sections和每个section中的rows。例如:
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
    NSInteger num =[self.settingCellTitles count]+1;
    return num;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else {
        NSInteger num =[[self.settingCellTitles objectAtIndex:section-1] count];
        return num;
    }
}- 实现 UITableViewCell,可以理解为每个row中的内容。
- 实现didSelectRowAtIndexPath,点击每个row的逻辑
要点
因为可以是一个section多个rows,也可能是多个sections,相当于一维数组和二维数组的区别。
对于一维数组获取row index:
 [[_settingCellModes objectAtIndex:indexPath.row] integerValue];对于二维数组:
[[[self.settingCellModes objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row] integerValue];主要就是先获取indexPath.section对应的section,而一维是直接
indexPath.row。