【发布时间】:2012-11-19 21:52:31
【问题描述】:
这让我很头疼:-)
我在 UIViewController 内有一个功能齐全的 CoreData Populated UITableView,我已经成功实现了“滑动删除选项”(这很容易),我还可以使用红色圆圈处的编辑按钮删除单个实例东西出现了。
我的问题是,我认为这是因为我有一个 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中,以便在单元格进入编辑模式或添加其他单元格装饰时自动调整。 -
我创建了一个新的自定义类并将它们从情节提要中拖到其中 - 我认为这意味着它们直接在单元格上,对吧??
-
我已经为我的自定义单元格添加了代码 - 我没有在 .m 文件中添加任何内容 - 直到现在都不需要。
-
我不使用Interface Build,所以我不知道该怎么做。我用代码做所有事情。对不起。
-
代码很好 :-) 我可以同时使用两者,代码会更好,这样我就可以理解幕后发生的事情:-)
标签: iphone ios uitableview edit custom-cell