【问题标题】:Different ViewController called when TableView is EditingTableView 正在编辑时调用不同的 ViewController
【发布时间】:2012-07-10 14:10:29
【问题描述】:

I have a simple grouped table view that when a cell is selected it pushes a View controller.导航栏的左侧项目将表格视图置于“编辑模式”。在编辑模式下,您可以根据需要移动和删除每个单元格。我想要的是能够在它处于编辑模式时推送一个单独的视图控制器,然后在它处于正常模式时。

这是视图控制器被推送的地方:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...stuff that doesnt matter...

[[self navigationController] pushViewController:detailViewController animated:YES];


}

BarButtonItems 在这里声明:

    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];

这是声明所有编辑内容的地方:

- (void)tableView:(UITableView *)atableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

if (editingStyle == UITableViewCellEditingStyleDelete)
{
    [atableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
}

- (void)tableView:(UITableView *)atableView 
moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath 
  toIndexPath:(NSIndexPath *)destinationIndexPath
{
[[BNRItemStore sharedStore] moveItemAtIndex:[sourceIndexPath row] 
                                    toIndex:[destinationIndexPath row]];
}

【问题讨论】:

    标签: objective-c ios xcode cocoa-touch editing


    【解决方案1】:

    当您在 didSelectRowAtIndexPath 中推送视图控制器时,您可以检查 tableview 是否处于编辑模式。如果是,您可以推送不同的视图控制器。

    - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
          ...stuff that doesnt matter...
             if(aTableView.editing) // The tableview is in editing mode
          [[self navigationController] pushViewController:otherViewController animated:YES];
          else [[self navigationController] pushViewController:detailViewController animated:YES];
    
    
    }
    

    editing 是一个属性,如果 tableview 当前处于编辑模式,则返回 YES。

    【讨论】:

    • 感谢您的帮助,但它似乎不起作用。我在编辑模式下无法选择表格单元格,我还没有制作视图控制器,但我做了 if(atableView.editing) { NSLog(@"editing")} 并且没有得到任何反馈......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2012-09-14
    • 2012-08-22
    相关资源
    最近更新 更多