2012-01-31 68 views
2

我正在开发一个iPhone应用程序,我有一个问题。我有几个编辑的行(UITableView幻灯片不可编辑行与可编辑的行Xcode iPhone

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{) 

和一个不可编辑一行一个UITableView,如果我点击编辑,在编辑的行有点向右滑动,并有一个红色的圆形按钮在它的左侧,但不可编辑的行不会滑动,有没有办法将它向右滑动但没有左边的红色按钮?目前看起来不太好,我希望有人可以帮助我这:) :)

+0

您是否使用自定义单元格,或者只是自定义一个内置的单元格? – dasblinkenlight 2012-01-31 16:59:28

回答

1

我不知道是否改变tableView的默认行为是一个好主意。 但是,如果你真的想,你可以使用缩进。

// Might be target of button 
- (void) setEditingMode 
{ 
    tableView.editing = YES; 
    [tableView reloadData]; 
} 

// Might be target of button 
- (void) resetEditingMode 
{ 
    tableView.editing = NO; 
    [tableView reloadData]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell* cell = ...; 
    .... 
    Boolean cellIsEditable = ...; 
    if(tableView.editing && !cellIsEditable) 
    { 
     cell.indentationWidth = ...; // (please experiment to find the exact value) 
     cell.indentationLevel = 1; 
    } 
    else 
    { 
     cell.indentationLevel = 0; 
    } 
} 
+0

哦对不起,我忘了说它是一个分组tableView。但这只会将文本滑动到右侧,但单元格仍为全尺寸:S – kjeldGr 2012-01-31 21:06:24

+0

我自己解决了问题:)但仍感谢您的帮助!:) – kjeldGr 2012-01-31 21:23:55

+0

@kjeldGr - 解决方案是什么?如果你愿意,你可以回答你自己的问题(并使用投票计数下方的勾号将其标记为答案),这样可以帮助其他人在这个问题上遇到困难 – Robotnik 2012-08-16 05:38:46

0

子类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。我尝试了很多价值观,直到找到有用的东西(价值对我来说毫无意义)。