2012-12-13 68 views
7

我实现了moveRowAtIndexPath来重新排列UITableView中单元格的顺序,并设置UITableViewCellEditingStyleNone,以便在编辑模式下仅显示重新排序控件。显示UITableViewCell重排序控制,而不将单元格内容向右移动?

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    return UITableViewCellEditingStyleNone; 

} 

它工作正常,但在编辑模式进入时,它仍然缩进每个单元格的内容,希望以腾出空间给一个缺失或插入的控制权。我没有使用,所以它变成了一个奇怪的空白空间。有没有办法在编辑模式下避免这种行为?

回答

4

您是否尝试过在您的UITableViewCell上设置shouldIndentWhileEditing为NO?

+2

非常感谢。根据你的回答,我发现UITableViewDelegate方法tableView:shouldIndentWhileEditingRowAtIndexPath:它为所有单元格设置选项。 –

4

试试这个UITableViewDelegate方法。它将允许重新排序而不显示左边的删除按钮,而不会将行移到右侧:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return UITableViewCellEditingStyleNone; 
} 

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    return NO; 
} 

- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 
+0

考虑提供一个解释你的代码 – arghtype

+0

请查看官方的苹果开发者文档的最好理解 1. UITableViewDataSource协议:HTTPS://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/ 2. UITableViewDelegate协议:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/ – Evana

相关问题