源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

iOS开发之UITableView左滑删除等自定义功能

  • 时间:2022-01-25 01:52 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS开发之UITableView左滑删除等自定义功能
[b]前言[/b] 相信每位iOS开发者都知道UITableView的左滑删除功能非常的炫酷,有时候左滑需要的功能不止只有删除一个,有时候会有顶置之类的别的功能,这时候就需要我们自己定制左滑 [b]示例代码[/b]
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
 
 UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                   title:@"取消收藏" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                    NSLog(@"收藏点击事件");
                    
                   }];
  
 UITableViewRowAction *rowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                   title:@"顶置" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                    NSLog(@"顶置按钮点击事件");
                    
                   }];
 
 rowAction.backgroundColor =RGB(215, 59, 16);
  
 NSArray *arr = @[rowAction,rowAction2];
 return arr;
}
[b]总结[/b] 我们可以利用UITableViewRowAction 创建对象,后面的代码块就是点击后执行的方法,创建完的对象加到数组中,这样的话我们就可以随意定制,颜色我们也可以自己选择,非常的方便。以上就是这篇文章的全部内容,希望能对大家的学习或者工作带来一定的帮助,如果有疑问大家可以留言交流。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部