这是做我的头:-)自定义的UITableViewCell在编辑模式
不动我的UILabels我有一个功能齐全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;
}
-
//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
-
- (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;
}
是你的标签直接添加到细胞还是你将它们添加到单元格的'contentView'?他们应该在'contentView'中让他们在单元格进入编辑模式或添加其他单元格装饰时自动进行调整。 – rmaddy
我创建了一个新的自定义类并将它们拖入Storyboard中 - 我认为这意味着它们直接位于单元格右侧? –
我已经添加了我的自定义单元的代码 - 我没有在.m文件中添加任何内容 - 现在不需要直到现在。 –