实现监听,使用tableview代理
代理方法:
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- NSLog(@"选中了第%d组的第%d行",indexPath.section,indexPath.row);}
- - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
- NSLog(@"取消选中了第%d组的第%d行",indexPath.section,indexPath.row);}
alertView.tag = indexPath.row;
实现alertview的监听方法
(void)alertView:(UIAlertView *)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex{
//点击了取消
if (buttonIndex == 0) return;
}
修改数据或者相应的操作。
一个问题:reloadData刷新会将视野内的所有cell全部刷新,造成了内存浪费,这个用于刷新内容多的时候。
可以使用局部刷新来解决这个问题:只重新加载选中的cell。
局部刷新还可以使用动画:
注意要传入刷新的组的数组的IndexPath,事先创建一个indexPath再传入,后面的值还可以设定动画。
为什么不直接改cell:因为cell的数据来自模型,模型不改,cell再次刷新还会变回模型的数据。