编辑模式下的自定义UITableViewCell不会移动我的UILabel

jwk*_*knz 9 iphone edit uitableview custom-cell ios

这是我的头脑:-)

我有一个功能齐全的CoreData填充UITableView内部UIViewController,我已经成功实现了"滑动删除选项"(这很简单),我还可以删除单个实例,其中有一个编辑按钮,红色圆圈内容出现.

我的问题是,我认为这是因为我有一个CustomCell,当我按下编辑按钮时,UILabels不要向右移动.

我尝试过使用-(void)layoutSubViews和其他一些,但没有任何作用.

我已经发布了我的代码cellForRowAtIndexPath.这是我的应用程序中的注释部分的一部分.这段代码有效,我只需要知道当我进入编辑模式时如何移动标签?

谢谢你的提示和建议:-)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";

MNCustomCell *cell = [_mainTableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
    cell = [[MNCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}


//cell.textLabel.text = [_tableArray objectAtIndex:indexPath.row];

MNotes *mnotes = [[self fetchedResultsController] objectAtIndexPath:indexPath];

cell.noteTitle.text = mnotes.noteTitleString;
cell.noteSummary.text = mnotes.mainNoteString;

mnotes.createDate = [[NSDate alloc] init];
SORelativeDateTransformer *relativeDateTransformer = [[SORelativeDateTransformer alloc] init];
NSString *relativeDate = [relativeDateTransformer transformedValue:mnotes.createDate];

cell.noteDate.text = relativeDate;


cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}
Run Code Online (Sandbox Code Playgroud)

-

//This is the Custom Cell
@interface MNCustomCell : UITableViewCell
{

}

@property (strong, nonatomic) IBOutlet UILabel *noteTitle;
@property (strong, nonatomic) IBOutlet UILabel *noteDate;

@property (strong, nonatomic) IBOutlet UITextView *noteSummary;


@end
Run Code Online (Sandbox Code Playgroud)

-

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    // Initialization code

    [self.contentView addSubview:_noteTitle];
    [self.contentView addSubview:_noteSummary];
    [self.contentView addSubview:_noteDate];

  }
   return self;
  }
Run Code Online (Sandbox Code Playgroud)

Fre*_*rik 9

另一种解决方案可能会起作用,但这种方式会自动为您完成动画. MNCustomCell不会根据单元格的当前状态重新布局视图,但如果将标签添加到单元格的contentView,它将会.

以下示例将移动标签,以便它不会干扰删除按钮.

MNCustomCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)]];
        mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:mainLabel];
Run Code Online (Sandbox Code Playgroud)