【问题标题】:When editing UITableView, clicking red dot fails to display 'Delete' button编辑 UITableView 时,点击红点无法显示“删除”按钮
【发布时间】:2011-03-18 17:00:35
【问题描述】:

表格视图包含在常规视图中。
正如预期的那样,点击“编辑”按钮(在该表格视图中)为每一行显示“带减号的红点”(即方法“setEditing”执行正常)。
但是,单击此类红点不会显示相应的“删除”按钮(“commitEditingStyle”不会执行)。
任何想法可能是错误的(见下面的相关代码)?

//---- RootViewController.h ----
@interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate> {    //used to be a 'UITableViewController'. Changed to UIViewController and rewired so I could add an iAd banner and the tableView to it. Before that change, issue was not present (commitEditingStyle below used to work).
...
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;   

//----- RootViewController.m ----
- (void)viewDidLoad {
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 
    ...
}
- (void) setEditing:(BOOL)editing animated:(BOOL)animated {    //Added so clicking 'Edit' displays red dots that rotate on tap (as expected).
    [super setEditing:editing animated:animated];         
    [self.tableView setEditing:editing animated:animated];
    if (editing) {                                           
        NSLog(@"RootViewController setEditing");             //Executes OK.
    }
}
- (void)tableView:(UITableView *)tableView                  //Clicking a red dot no longer executes this method (so, does not display 'Delete' red button).
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  
forRowAtIndexPath:(NSIndexPath *)indexPath {         

    NSLog(@"RootViewController commitEditingStyle");           //Does NOT execute.
    ...
}

【问题讨论】:

  • 使表格单元格看起来像的代码是什么?它们是如何布局的?
  • 连接和单元格:web.me.com/gguglielmo/Q/Q1.html
  • 你有没有弄清楚这里发生了什么?

标签: iphone cocoa-touch ios4


【解决方案1】:

仔细检查您是否已将表格的 UITableViewDelegate 和 UITableViewDataSource 正确连接到您编写的新 UIViewController。

【讨论】:

  • 连接和单元格布局(在 web.me.com/gguglielmo/Q/Q1.html 中)显示了文件所有者的数据源和委托出口连接到表视图。表格单元格是直截了当的(并且没有更改)。
【解决方案2】:

确保cell.editingAccessoryView 在以下位置设置为零:

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
 cell.editingAccessoryView = nil;
}

【讨论】:

    【解决方案3】:

    你没有在你的 .h 中实现 tableView 协议。你的类接口应该是这样的

    @interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate, UITableViewDelegate,UITableViewDataSource>
    

    【讨论】:

      猜你喜欢
      • 2017-09-28
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多