iOS TableView 多行選擇實現

iOS TableView 多行選擇實現

###設置TableView能夠多行選擇,這裏有2中方法能夠實現代理

  • 1.實現TableView的代理方法editingStyleForRowAtIndexPath:,返回值返回UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert(若是隻返回Delete,是單行刪除模式;若是隻返回Insert是插入模式)
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 1.實現這一個代理方法,返回2個值
    return UITableViewCellEditingStyleDelete|
    UITableViewCellEditingStyleInsert;
}
  • 2.設置TableView的allowsMultipleSelectionDuringEditing屬性爲YES
self.tableView.allowsMultipleSelectionDuringEditing = YES;

這樣,當TableView進入編輯模式的時候就會顯示爲多選模式。code

###PS: 另外能夠自定義選中時「對號」的顏色,代碼以下:ip

self.tableView.tintColor = [UIColor redColor];
相關文章
相關標籤/搜索