UITableView
核心的思路就是维护一个数组,记录所有选中的cell的indexpath,使用时,根据这个数组来取出datasource中对应的数据项。
核心要点
1. tabview的cell的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//根据tabview和indexpath获取对应点击的cell
//进行事件处理
}
2. 改变cell的状态
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
//设置为未选中状态
cell.accessoryType=UITableViewCellAccessoryNone;
//设置为已选中状态
cell.accessoryType==UITableViewCellAccessoryCheckmark;
3. cell状态初始化
对于默认就选中的项目,或者在tabview还未初始化时就已经选中的项目,还需要在cell的初始化方法
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中对cell的初始化状态进行设置。