tableView多選cell選中樣式(有的是多選樣式,有的是正常樣式)

在實際的過程中,我們或多或少能遇到這樣的圖,就是上邊紅框固定,但是底下的要顯示可選狀態,這個一共有兩種方法

  • 1.將紅框設置為tableview.tableheaderview
  • 2.全用cell
公司要這樣的UI效果

我是比較推薦使用第二種方法,第一種或多或少有的不明智,現在聊聊如何通過第二中方法制作的

*1.設置self.tableView.editing = YES;(一定要有這一步,否則無效)

*2.設置好要去現實的cell樣子


//設置數據源,以及返回cell的樣子
- (void)setupTableViewFirstSec{
    
    SEUsePlatAddFriendModel * friendsNewM = [[SEUsePlatAddFriendModel alloc] init];
    friendsNewM.imgstr = @"contact_cell_newfriends";
    friendsNewM.appName = @"搜索";
    
    SEUsePlatAddFriendModel * mygroupM = [[SEUsePlatAddFriendModel alloc] init];
    mygroupM.imgstr = @"contact_cell_mygroup";
    mygroupM.appName = @"已加入的群組";
    
    self.firstSecArr = @[friendsNewM,mygroupM];
    
    [self.beGroupedFriends addObject:self.firstSecArr];
    
}

#pragma mark - 內部方法
- (void)jumpToSearchVC:(UIGestureRecognizer *)tap{
    SEEntireSearchController *searchVC = [[SEEntireSearchController alloc] initWithIsInTwitter:NO];
    [self.navigationController pushViewController:searchVC animated:YES];
}
#pragma mark - 數據源方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SEPhoneLinkManCell *cell = [SEPhoneLinkManCell phoneLinkManCellWithTableView:tableView];
    NSArray *t = self.beGroupedFriends[indexPath.section];
    if (indexPath.section==0) {
        if (indexPath.row == 0) {
            UITableViewCell *sCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                                            reuseIdentifier:nil];
            SESearchView *sV = [[SESearchView alloc] init];
            [sCell.contentView addSubview:sV];
            sV.frame = CGRectMake(0, 0, ScreenWidth, kSEPhoneLinkManCellHeightIInMyContacts);
            [sV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(jumpToSearchVC:)]];
            cell = sCell;
        }else{
            cell.assModel = t[indexPath.row];
            cell.tintColor = [AppConfig colorForEa5757];
        }
    }else{
        cell.profile = t[indexPath.row];
        cell.tintColor = [AppConfig colorForEa5757];
    }
    return cell;
}

*3.通過代理方法確定那個可以滑動,那個不可以滑動

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return NO;
    }else{
        return YES;
    }
}

*4.確定如果可以滑動,他要顯示的樣式

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return UITableViewCellEditingStyleNone;
    }else{
        return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
    }
}

說在后邊
為啥self.tableView.editing = YES;一定要寫?

就會顯示不正確,和沒有設置一樣的效果

有其他操作,或者替換圖片的需求,可以看看這個文章。iOS自定義tableView多選cell選中樣式

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容