iPhone:如何更改 UITableViewCell 中默认删除按钮的框架

标签 iphone uitableview

我面临的问题是有没有办法改变默认框架 UITableView 中的删除按钮,还有一件事是删除按钮始终显示在 UITableViewcell 的单元格中心,因此可以通过任何方式更改删除按钮的框架。

// Update the data model according to edit actions delete or insert.
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        [appDelegate.categories removeObjectAtIndex:indexPath.row];
        [categoryTableView reloadData];
    } 
}

#pragma mark Row reordering
// Determine whether a given row is eligible for reordering or not.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{   
    return YES;
}

// Process the row move. This means updating the data model to correct the item indices.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath 
      toIndexPath:(NSIndexPath *)toIndexPath 
{
    NSString *item = [[appDelegate.categories objectAtIndex:fromIndexPath.row] retain];
    [appDelegate.categories removeObject:item];
    [appDelegate.categories insertObject:item atIndex:toIndexPath.row];
    [item release];
}

提前致谢。

最佳答案

在 ios 6.1 中我无法使用上面的代码。我看到了几个建议对单元类进行子类化并提供自定义 -willTransitionToState 的答案。更改 subview /按钮 View 框架不会有效地更改其显示位置。

但是,如果您重写 layoutSubviews 方法,它将起作用。这是代码:

//below i moved the delete button to the left by 10 points. This is because my custom tableview has lef

- (void)layoutSubviews
{
    [super layoutSubviews];
    for(UIView *subview in self.subviews)
    {
        if([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
        {
            CGPoint o = subview.center;
            subview.center = CGPointMake(o.x - 10, o.y);
        }
    }
}

关于iPhone:如何更改 UITableViewCell 中默认删除按钮的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7606276/

相关文章:

iphone - 如何实际实现Apple示例中的分页UIScrollView?

iphone - Objective-C:为什么@synthesize 预见到一个赋值?

iphone - UIScrollView View

ios - 如何在 UITableViewCell 上实现滑动动画

ios - 从自定义 UitableViewCell 中保存 textField.text

iphone - tableViewController 中的多线程奇怪延迟

ios - 在上一个 View 的顶部打开 Storyboard

swift - 如何在披露指示器上启用用户交互,但不在 UITableViewCell 上启用

ios - UITableView过滤数据的索引不正确

ios - UITableViewCell错误ios7