iPhone:如何在UITableViewCell中更改默认删除按钮的框架 [英] iPhone:How to change default delete button's frame in UITableViewCell
问题描述
我面临的问题是,有没有办法在 UITableView
中更改默认帧
的删除按钮,还有一件事就是删除按钮总是显示在 UITableViewcell
的单元格中心,以便更改删除按钮的框架。
I have facing problem is that Is there any way to change default frame
of delete button in UITableView
and one more thing is that delete button is always display in center of cell of UITableViewcell
so any way to change frame of delete button.
// 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];
}
提前致谢。
推荐答案
我无法使用上述代码。我已经看到了几个答案,建议子类化单元格类并提供自定义 - willTransitionToState
。更改子视图/按钮视图框不会有效地改变它的显示位置。
in ios 6.1 i was not able to use the above code. I've seen several answers that suggests subclassing the cell class and providing a custom -willTransitionToState
. Changing the subview/buttonview frame does not affectively change it's displayed position.
但是如果你覆盖 layoutSubviews
方法它将工作。这是代码:
However if you override the layoutSubviews
method it will work. Here is the code:
//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中更改默认删除按钮的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!