3

我正在玩移动 uitableviewcells,无论出于何种原因,

- (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

编译时没有警告。

谢谢!

4

4 回答 4

6

您需要在编辑模式下将多选设置为 NO

self.tableview.allowsMultipleSelectionDuringEditing = NO;
于 2014-12-25T13:54:44.593 回答
2

尝试正确大写方法名称

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

那就是大写的Sin 。editingStyleForRowAtIndexPathObjC 选择器区分大小写。表视图不认为它的委托响应您尝试提供返回值的方法。

于 2010-02-09T03:21:48.183 回答
1

另一个原因可能是您还需要实施

- (void)tableView:(UITableView *)tableView
  commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
  forRowAtIndexPath:(NSIndexPath *)indexPath
于 2015-08-19T08:18:09.343 回答
0

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

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

于 2013-08-31T01:29:58.733 回答