【问题标题】:Reorder control isn't displayed on table view重新排序控件未显示在表格视图上
【发布时间】:2011-06-13 18:07:20
【问题描述】:

我创建了一个基于导航应用程序模板的 iOS 应用程序,该应用程序由 Core Data 框架支持。

单击“编辑”按钮时,我希望行可以重新排序和删除。

在构建单元格时,我添加了这一行:

cell.showsReorderControl = YES;

tableView:canMoveRowAtIndexPath: 方法返回YES。

但是重新排序控件没有显示在行中,我错过了什么吗?

【问题讨论】:

    标签: iphone cocoa-touch ios uitableview core-data


    【解决方案1】:

    来自UITableViewCell showsReorderControl docs

    要显示重新排序控件,您不仅要设置此 属性,但实现 UITableViewDataSource 方法 表视图:moveRowAtIndexPath:toIndexPath:。此外,如果数据 source 实现 tableView:canMoveRowAtIndexPath: 返回 NO,则 重新排序控件未出现在该指定行中。

    【讨论】:

    • 我不知道必须实现 tableView:moveRowAtIndexPath:toIndexPath: 才能使移动附件出现。这解决了我的问题!谢谢!
    【解决方案2】:

    UITableView 还必须处于编辑模式,默认情况下不处于该模式。通常您使用按钮或其他控件在编辑模式之间切换。将表格视图置于编辑模式(我们假设您有一个 UITableViewController 并且您的 tableView 属性已正确设置,如果没有,请根据您的环境进行调整):

    // This line somewhere inside the UITableViewController will
    // animate in the various editing controls and make sure they
    // show up on your table.
    [[self tableView] setEditing:YES animated:YES];
    

    【讨论】:

    【解决方案3】:

    试试这个。 . .您必须实现这两种方法才能在编辑模式下获得重新排序控件

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多