OGeek|极客世界-中国程序员成长平台

标题: ios - 限制 UITableViewCell 在特定部分移动 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:51
标题: ios - 限制 UITableViewCell 在特定部分移动

- (BOOL)tableViewUITableView *)tableView canMoveRowAtIndexPathNSIndexPath *)indexPath 
{
   if (indexPath.section == 1) {
        return NO;
   }
   else {
        return YES;
   }
}

- (BOOL)tableViewUITableView *)tableView canEditRowAtIndexPathNSIndexPath *)indexPath 
{
     if (indexPath.section == 1) {
            return NO;
     }
     else {
            return YES;
     }
}

我的 tableView 中有 2 个部分。我希望我的 tableViewcells 仅在第一部分移动(而不是第二部分)。目前,如果我将 tableCell 拖到第二部分,它会崩溃。



Best Answer-推荐答案


我想你正在寻找这种方法 -

- (NSIndexPath *)tableViewUITableView *)tableView targetIndexPathForMoveFromRowAtIndexPathNSIndexPath *)sourceIndexPath toProposedIndexPathNSIndexPath *)proposedDestinationIndexPath
{
   if (proposedDestinationIndexPath.section != 0)
   {
       return sourceIndexPath;
   }

   return proposedDestinationIndexPath;
 }

它将限制您仅在第 0 节中移动行。如果您尝试将行从第 0 节移动到第 1 节,它将返回单元格的前一个索引路径

关于ios - 限制 UITableViewCell 在特定部分移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24881090/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4