gpt4 book ai didi

ios - TableView setEditing 还启用行删除

转载 作者:行者123 更新时间:2023-11-29 10:43:44 24 4
gpt4 key购买 nike

我想重新排列我的表格 View 中的行。我已经实现了这两个方法。

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{
NSLog(@"Move Row At IndexPath");
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{

NSLog(@"Can Move Row At IndexPath");
if(indexPath.section == 0 || (indexPath.section == 1 && indexPath.row == 0)){
NSLog(@"Don't Move");
return NO;
}
return YES;

}

现在我只想重新排序单元格而不希望用户删除单元格。但是当我启用编辑 [tableView setEditing:yes animated:YES]; 然后它还允许用户从 TableView 中删除项目我只想在 TableView 中显示重新排序控件,比如一个在 iphone 设置 -> 通知中心,然后按编辑。

有些人可以知道如何做到这一点。

谢谢

最佳答案

尝试以这种方式实现

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

// method to remove "-" sign from editing mode
-(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;
}

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
// Update your datasource here and work accordingly......>
}

关于ios - TableView setEditing 还启用行删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23214992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com