使用自定义按钮重新排序 tableview 单元格 [英] Reorder tableview cell with a custom button

查看:47
本文介绍了使用自定义按钮重新排序 tableview 单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我有一个 UITableView,我正在使用以下代码来管理重新排序:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{返回是;}- (UITableViewCellEditingStyle)tableView:(UITableView *)tableVieweditingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {返回 UITableViewCellEditingStyleNone;}-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{if(proposedDestinationIndexPath.section==0 &&proposedDestinationIndexPath!=sourceIndexPath){返回建议的DestinationIndexPath;}别的{返回源索引路径;}}-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{返回是;}-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{//移动行}

它工作正常,但我想更改重新排序按钮的位置并在 iOS 8.4 上实现类似音乐队列列表的功能.

我想将重新排序按钮更改为单元格内容所在的滚动视图并随单元格移动.截屏:

提前致谢:)

解决方案

我使用这里的代码解决了我的问题

a> 用于重新排序,然后我使用 UITableView 委托如下进行滑动删除.

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableVieweditingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{返回 UITableViewCellEditingStyleDelete;}-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{//从tableview和数据源中删除选定的单元格}}

I'm developing an application an I have a UITableView, I am using the following code to manage reordering:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleNone;
}
-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{
if(proposedDestinationIndexPath.section==0 && proposedDestinationIndexPath!=sourceIndexPath){

    return proposedDestinationIndexPath;
}
else{
    return sourceIndexPath;
   }
}
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ 
   return YES;
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
  //move rows
}

it works fine, but I want to change the Reorder button position and implement something like Music queue list on iOS 8.4.

I want to change the reorder button to be on the scrollview which contents of the cell are and move with the cell. Screenshot:

Thanks in advance :)

解决方案

I solved my problem using the code here for reordering and then I used UITableView delegates as follow for swipe to delete.

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    //Remove selected cell from tableview and you data source
  }
}

这篇关于使用自定义按钮重新排序 tableview 单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆