//解决scrollView上面的 tableView 滑动冲突 设置一下连个属性 来个控件的滑动事件就不会冲突了
[scr setDelaysContentTouches:NO];
[scr setCanCancelContentTouches:NO];
//根据indexPath 来获取cell
UITableViewCell*cell=[tableView cellForRowAtIndexPath:indexPath];
//根据点击的cell 获取indexPath
NSIndexPath*indexPath=[self.tableView indexPathForSelectedRow];
//确定cell上的按钮在哪行
- (void)button:(id)sender {
UITableViewCell * cell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath * path = [self.tableView indexPathForCell:cell];
NSLog(@"index row%d", [path row]);
}
//关闭弹簧效果
_accTableView.bounces = NO;
//设置交替色
cell.backgroundColor = (indexPath.row%2)?[UIColor lightGrayColor]:[UIColor grayColor];
设置cell点击没有选中效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
设置是否可以滑动属性
tab.scrollEnabled = NO;
设置内容和边的间距
m_tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);
m_tableView.scrollIndicatorInsets = UIEdgeInsetsMake(44, 0, 0, 0);
设置分割线
UIBlurEffect *blurEffect =[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
_listView.separatorEffect = blurEffect;
Tableview右面的箭头可以自己放一个UIView或者它的子类
if (indexPath.section == 0) {
self.swith = [[UISwitch alloc]initWithFrame:CGRectMake(260, 10, 0, 0)];}
下面的这句话就是把一个选择器放在了箭头的位置
cell.accessoryView = self.swith;
也可以自定义箭头
UIImageView *arrow = [[UIImageView alloc]initWithFrame:CGRectMake(285, 20, 8, 14)];
arrow.image = [UIImage imageNamed:@"5_进入"];
cell.accessoryView = arrow;
实现Cell的滑动删除
需要实现UITableView的代理UITableViewDelegate中如下方法:
先要设Cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
定义编辑样式改变左侧的按钮的样式 删除是'-' 增加是'+'
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setEditing:YES animated:YES];
return UITableViewCellEditingStyleDelete;
}
进入编辑模式,按下出现的编辑按钮后
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setEditing:NO animated:YES];
}
以下方法可以不是必须要实现,添加如下方法可实现特定效果:
修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
实现Cell可上下移动,调换位置,需要实现UiTableViewDelegate中如下方法:
先设置Cell可移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
当两个Cell对换位置后
- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath
{
}
设置进入编辑状态时,Cell不会缩进
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
在下面方法中添加 cell.showsReorderControl =YES;
使Cell显示移动按钮
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;