uitableView实现多选

来源:互联网 发布:js传值input 编辑:程序博客网 时间:2024/05/24 03:23

你已经知道,表格单元可以通过accessoryType属性,显示一个对号标记的附件。当用户选中一个单元格时,表格代理的didSelectRowAtIndexPath方法会被调用。这个方法是UITableViewDelegate协议的一部分。在你的代理中加入这个方法,并且对需要的单元格设置对号附件,就可以为你的表格增加对多选的支持:

  1. - (void)tableView:(UITableView *)tableView  
  2.     didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  3. {  
  4.     NSLog(@'Selected section %d, cell %d',  
  5.         [ indexPath indexAtPosition: 0],  [indexPath indexAtPosition: 1 ]);  
  6.  
  7.     /* 得到选中的表格单元的指针 */  
  8.     UITableViewCell *cell = [self.tableViewcellForRowAtIndexPath: indexPath ];  
  9.  
  10.     /* 切换附件的类型 */  
  11.     if (cell.accessoryType == UITableViewCellAccessoryNone)  
  12.         cell.accessoryType = UITableViewCellAccessoryCheckmark;  
  13.     else  
  14.         cell.accessoryType = UITableViewCellAccessoryNone;  
0 0
原创粉丝点击