子类UITableViewCell并自己滑动不可编辑的行。
@interface MyHistoryTableViewCell : UITableViewCell
@end
@implementation MyHistoryTableViewCell : UITableViewCell
#define CELL_SLIDE_WIDTH 32 // found empirically
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if (self.editingStyle == UITableViewCellEditingStyleNone) { // not editable
CGRect frame = self.frame;
UITableView *tableView = ((UITableView *)(self.superview));
if (tableView.editing) { // going to editing mode
frame.origin.x = CELL_SLIDE_WIDTH;
frame.size.width = tableView.frame.size.width - CELL_SLIDE_WIDTH;
} else { // ending editing
frame.origin.x = 0;
frame.size.width = tableView.frame.size.width;
}
[UIView animateWithDuration:0.3 animations:^{ // match the tableView slide duration
self.frame = frame;
}];
}
}
@end
如果您有需要被固定在单元格的权利(例如,一个按钮,应该不会滑动)子视图,然后做
mySubview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; // anchors to the right margin
另外,你必须要创新的时候设置子视图的frame.origin.x。我尝试了很多价值观,直到找到有用的东西(价值对我来说毫无意义)。
您是否使用自定义单元格,或者只是自定义一个内置的单元格? – dasblinkenlight 2012-01-31 16:59:28