2010-01-30 67 views
0

我有最后一个问题,是我杀了。 我正在玩一个使用tableView:accessoryTypeForRowWithIndexPath方法的旧项目,其中我试图在没有它的情况下重写应用程序。iphone(objective-c)附件修改错误

我删除了tableView:accessoryTypeForRowWithIndexPath方法,但我的心不是解决方案的工作,只是还没有。

的问题是,现在当我按我的DetailViewController查看“编辑”按钮,在“编辑”附件类型不显示。

下面是我实际的代码,我已经还包括project file对于这一点,因为我绝望了一个可行的解决方案。

我的问题是,我有什么代码更改,让附件改变,并没有其他影响。 (我知道RootViewController的作品,但我怎么能得到DetailViewController表做?)

问候,@norskben

项目文件下载:Get it here.

setEditing

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    [self.navigationItem setHidesBackButton:editing animated:animated]; 

    [tableView reloadData]; 
} 

cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
     cell.editingAccessoryType = UITableViewCellAccessoryCheckmark; 
    } 

    switch(indexPath.section) { 
     case 0: 
      cell.textLabel.text = coffeeObj.coffeeName; 
      break; 
     case 1: 
      cell.textLabel.text = [NSString stringWithFormat:@"%@", coffeeObj.price]; 
      break; 
    } 

    return cell; 
} 

项目文件下载:Get it here.

回答

1

在你setEditing:animated:方法,你正在做的,你是真的不应该做两件事情。重新加载表格数据是没有意义的。如果您必须手动更改标签栏中的按钮,那么您还没有正确设置它们。系统为你照顾。如果您已经正确设置了编辑按钮,那么您甚至不必手动实际拨打setEditing:animated:

我想你应该了解一些UITableView示例代码。

+0

奇怪的是,你在正确的方向小刺固定的这一切。我是比较样本,发现我的DetailViewController是一个UIViewController而不是UITableViewController。 (接口生成器我链接视图与tableview,(从初始视图))。我在代码和界面构建器中进行了更改,然后配件开始工作!接下来我做的是添加一些代码来删除没有行删除的红色侧图标,最后一点是拼图的添加self.tableView.allowsSelectionDuringEditing = YES; //在viewDidLoad中取消添加。非常感谢。 – oberbaum 2010-01-30 23:06:34