做侧滑的时候发现一个问题,当一个UITableView的cell有的有侧滑,有的没有,当用editActionsForRowAtIndexPath方法的时候发现有点问题,查看了下api,需要用到canEditRowAtIndexPath这个方法

#import "SkidSidewaysViewController.h"

@interface SkidSidewaysViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *dataArr;
@property(nonatomic,strong)UITableView *tableView;
@end @implementation SkidSidewaysViewController
#define Identifier @"cell"
-(NSMutableArray *)dataArr{
if(!_dataArr){
_dataArr = [NSMutableArray array];
for(int i=0;i<20;i++){
[_dataArr addObject:[NSString stringWithFormat:@"%d",arc4random()%3]];
}
}
return _dataArr;
} - (void)viewDidLoad {
[super viewDidLoad];
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:Identifier];
}
#pragma mark UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier forIndexPath:indexPath];
cell.textLabel.text = self.dataArr[indexPath.row];
return cell;
}
//判断是否有侧滑
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if([self.dataArr[indexPath.row] isEqualToString:@"0"]){
return NO;
}
return YES;
}
//判断侧滑按钮一共有几个
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray *acitonArr = [NSMutableArray array];
for(int i=0;i<[self.dataArr[indexPath.row] intValue];i++){
UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:[NSString stringWithFormat:@"%d",i] handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { }];
action.backgroundColor = [UIColor redColor];
[acitonArr addObject:action];
} return acitonArr;
}
@end

最新文章

  1. Robot Framework 的安装和配置(转载)
  2. mysql操作查询结果case when then else end用法举例
  3. android .9图的作用
  4. GMap.Net开发之在WinForm和WPF中使用GMap.Net地图插件
  5. HTML5客户端数据存储
  6. phalcon: 获取参数的方法
  7. Binary Tree Level Order Traversal II [LeetCode]
  8. C# redis 分布式session存储
  9. ContentProvider深度探索
  10. Android OOM 解决方案
  11. 修改host文件的P处理
  12. Nginx特点
  13. hexo 博客支持PWA和压缩博文
  14. java equals和hashcode方法
  15. 浮动、清除浮动、BFC
  16. 网络编程_TCP协议_客户端与服务端
  17. MONGOOSE – 让NODE.JS高效操作MONGODB(转载)
  18. CH0102 64位整数乘法 数论
  19. dTree无限级文件夹树和JQuery同步Ajax请求
  20. 那些H5用到的技术(5)——视差滚动效果

热门文章

  1. mongodb查询数据库中某个字段中的值包含某个字符串的方法
  2. 转:Python语言编程学习资料(电子书+视频教程)下载汇总
  3. python加快数据处理的方法
  4. ubuntu 创建swap分区
  5. VS Release模式调试
  6. gitlab图形化使用教程 (mtm推荐)
  7. File not found 错误 nginx
  8. Python scipy 计算短时傅里叶变换(Short-time Fourier transforms)
  9. MySQL主从同步添加至zabbix监控
  10. 如何打jar包 学习笔记