在分组tableview中定位UITableViewCellEditingStyleDelete图标的好方法是什么?
问题描述:
作为标题,我可以将UITableViewCellEditingStyleDelete按钮/图标定位在分组的tableview的tableviewcell中,而不是在它之外吗?在分组tableview中定位UITableViewCellEditingStyleDelete图标的好方法是什么?
答
从Matt Gallagherblog post摘录揭示了一个方法
这是原代码模仿行为你不想:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[self setNeedsLayout];
}
- (void)layoutSubviews
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[super layoutSubviews];
if (((UITableView *)self.superview).isEditing)
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET;
self.contentView.frame = contentFrame;
}
else
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 0;
self.contentView.frame = contentFrame;
}
[UIView commitAnimations];
}
因此,如果我们做出了改变,我们可以把它做你想做的事:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[self setNeedsLayout];
}
- (void)layoutSubviews
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[super layoutSubviews];
if (((UITableView *)self.superview).isEditing)
{
//don't resize and and move your frame here
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 0;
self.contentView.frame = contentFrame;
}
else
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 0;
self.contentView.frame = contentFrame;
}
[UIView commitAnimations];
}
你一定会调整这个,但这是一个好的开始。
谢谢,我会试一试。 – Zteeth 2009-06-19 02:35:45