này được làm đầu tôi trong :-)Tuỳ chỉnh UITableViewCell trong chế độ chỉnh sửa không di chuyển UILabels tôi
Tôi có một CoreData đầy đủ chức năng Dân cư UITableView
bên trong một UIViewController
và tôi đã triển khai thành công "Vuốt sang Xóa tùy chọn" (đó là dễ dàng) và tôi cũng có thể xóa các trường hợp đơn lẻ bằng nút chỉnh sửa nơi vòng tròn màu đỏ thingy xuất hiện.
Vấn đề của tôi là, và tôi nghĩ đó là vì tôi có một CustomCell, khi tôi nhấn nút chỉnh sửa, UILabels
sẽ không di chuyển sang phải.
Tôi đã thử sử dụng -(void)layoutSubViews
và một vài loại khác, nhưng không có tác dụng.
Tôi đã đăng mã của mình cho số cellForRowAtIndexPath
. Đây là một phần của phần ghi chú trong ứng dụng của tôi. Mã này hoạt động, tôi chỉ cần biết Làm cách nào để di chuyển các nhãn khi tôi chuyển sang chế độ Chỉnh sửa ??
Cảm ơn bạn những lời khuyên và tư vấn :-)
- (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;
}
Are nhãn của bạn thêm trực tiếp vào tế bào hoặc bạn đã thêm chúng cho 'contentView' của tế bào? Chúng phải nằm trong 'contentView' để chúng tự động điều chỉnh khi di chuyển đến chế độ chỉnh sửa hoặc trang trí ô khác được thêm vào. – rmaddy
Tôi đã tạo một Custom Class mới và kéo chúng vào đó từ Storyboard - Tôi nghĩ điều đó có nghĩa là chúng trực tiếp trên ô phải không ?? –
Tôi đã thêm mã cho ô tùy chỉnh của mình - Tôi chưa thêm bất kỳ thứ gì trong tệp .m - không cần thiết để cập nhật ngay bây giờ. –