在實(shí)際的過程中,我們或多或少能遇到這樣的圖艘虎,就是上邊紅框固定唉侄,但是底下的要顯示可選狀態(tài),這個(gè)一共有兩種方法
- 1.將紅框設(shè)置為
tableview.tableheaderview
- 2.全用cell
公司要這樣的UI效果
我是比較推薦使用第二種方法野建,第一種或多或少有的不明智属划,現(xiàn)在聊聊如何通過第二中方法制作的
*1.設(shè)置
self.tableView.editing = YES;
(一定要有這一步,否則無效)
*2.設(shè)置好要去現(xiàn)實(shí)的cell樣子
//設(shè)置數(shù)據(jù)源候生,以及返回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 - 內(nèi)部方法
- (void)jumpToSearchVC:(UIGestureRecognizer *)tap{
SEEntireSearchController *searchVC = [[SEEntireSearchController alloc] initWithIsInTwitter:NO];
[self.navigationController pushViewController:searchVC animated:YES];
}
#pragma mark - 數(shù)據(jù)源方法
- (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.通過代理方法確定那個(gè)可以滑動(dòng)同眯,那個(gè)不可以滑動(dòng)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
return NO;
}else{
return YES;
}
}
*4.確定如果可以滑動(dòng),他要顯示的樣式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return UITableViewCellEditingStyleNone;
}else{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
}
說在后邊
為啥self.tableView.editing = YES;
一定要寫唯鸭?
就會(huì)顯示不正確须蜗,和沒有設(shè)置一樣的效果
有其他操作,或者替換圖片的需求目溉,可以看看這個(gè)文章明肮。iOS自定義tableView多選cell選中樣式