iphone - editStyleForRowAtIndexPath 没有被调用(因此显示删除按钮)

标签 iphone uitableview tablecell

我正在尝试移动 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

编译时没有警告。

谢谢!

最佳答案

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

self.tableview.allowsMultipleSelectionDuringEditing = NO;

关于iphone - editStyleForRowAtIndexPath 没有被调用(因此显示删除按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2226509/

相关文章:

iphone - 想要在 UIBarButtonItem 旁边添加 UIActivityIndi​​cator

iphone - 为使用 REST 服务的应用程序创建帐户的安全/最佳实践?

iPhone MKMapView强制标注气泡

ios - 点击并从一个 UITable 拖动到其下方的另一个 UITable

JavaFX 自定义 TableCell 监听

iphone - 在 UIWebView 中打开弹出链接,可能吗?

ios - 具有复杂单元格的 UITableView 缓慢且滞后

ios - 从核心数据中按日期对 TableView 进行排序 - Swift4

java - "Accounting"JavaFX 中的样式表单元格

iphone - UITableViewCell imageView.contentMode 在 3.0 中不起作用