2010-02-09 60 views
2

我玩弄移动uitableviewcells,以任何理由,editingStyleForRowAtIndexPath是没有得到所谓的(所以删除按钮被显示出来)

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
      editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleNone; //<-- bp set on it 
} 

是没有得到所谓的(我给自己定一个断点) - 所以表格显示删除选项,但我不想那样。这是我的实现:

@implementation MoveItController 
@synthesize mList; 

- (IBAction)moveButton 
{ 
    [self.tableView setEditing:!self.tableView.editing animated:YES]; 

    [self.navigationItem.rightBarButtonItem setTitle:(self.tableView.editing)? @"Done" : @"Move"]; 
} 

- (void)viewDidLoad 
{ 
    if (mList == nil) 
    { 
     mList = [[NSMutableArray alloc] initWithObjects:@"$1", @"$2", @"$5", @"$10", @"$20", @"$50", @"$100", nil]; 
    } 

    UIBarButtonItem *mvButton = [[UIBarButtonItem alloc] 
           initWithTitle:@"Move" 
           style:UIBarButtonItemStyleBordered 
           target:self 
           action:@selector(moveButton)]; 
    self.navigationItem.rightBarButtonItem = mvButton; 
    [mvButton release]; 
    [super viewDidLoad]; 
} 

// Table datasource methods 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [mList count]; 
} 

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


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moveItCellId]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moveItCellId] autorelease]; 
     cell.showsReorderControl = YES; 
    } 

    cell.textLabel.text = [mList objectAtIndex:[indexPath row]]; 
    return cell; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
      editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleNone; 
} 

- (BOOL)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath 
toIndexPath:(NSIndexPath *)toIndexPath 
{ 
    id object = [[mList objectAtIndex:[fromIndexPath row]] retain]; 
    [mList removeObjectAtIndex:[fromIndexPath row]]; 
    [mList insertObject:object atIndex:[toIndexPath row]]; 
    [object release];     
} 

- (void) dealloc 
{ 
    [mList release]; 
    [super dealloc]; 
} 

@end 

在编译时没有警告。

谢谢!

回答

2

尝试资本的方法名称正确

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
      editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 

,随着editingStyleForRowAtIndexPathS的资本。 ObjC选择器区分大小写。表视图不认为它的代表响应您尝试提供返回值的方法。

+0

妈 - 我喜欢特里普尔检查了!哈哈谢谢。我希望xcode发出警告,就像我认为它通常那样的类似方法签名一样。 +1谢谢。 – 2010-02-09 03:25:41

0

不调用editStyleForRowAtIndexPath(和其他委托)的另一个原因是如果控件没有将它的委托出口连接到文件的所有者。

是的,这很明显,但很容易被忽视。

4

您需要多次选择设置为NO在编辑模式

self.tableview.allowsMultipleSelectionDuringEditing = NO; 
1

另一个原因可能是,你还需要实现

- (void)tableView:(UITableView *)tableView 
    commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
    forRowAtIndexPath:(NSIndexPath *)indexPath 
+0

这是我的问题:..当你删除这个方法('commitEditingStyle'),然后在'editingStyleForRowAtIndexPath'中放置一个断点时,它将不会再被调用,并且默认的编辑风格变为无 – matrix4use 2015-09-22 23:45:14