我已經研究過這個過程,但似乎沒有找到解決方案。我有一個自定義的UITableViewCell(具有各種子視圖,包括單選按鈕,標籤等)。當表格視圖設置爲編輯時,我希望+和 - 插入/刪除編輯控件出現在單元格的最左側部分。編輯自定義UITableViewCell時不會出現插入/刪除編輯控件
如果我使用標準的UITableViewCell,這可以很好地工作。但是,在使用自定義單元格時,控件不會顯示。任何人有任何想法如何解決同樣的問題嗎?
下面是我的表視圖代碼中的一些快照....
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.isEditing) {
if ([tableView isEqual:self.tableView]) {
if (editingStyle == UITableViewCellEditingStyleInsert) {
// ...
}
else if (editingStyle == UITableViewCellEditingStyleDelete) {
// ...
}
}
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView isEqual:self.tableView]) {
if (indexPath.row == 0) {
return UITableViewCellEditingStyleInsert;
}
else {
return UITableViewCellEditingStyleDelete;
}
}
else {
return UITableViewCellEditingStyleNone;
}
}
而定製的表視圖單元代碼...
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[self setNeedsLayout];
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self configureConstraints];
}
- (void)configureConstraints
{
// This is where the cell subviews are laid out.
}
謝謝@rmaddy ...這完美的作品!我在這個超級小姐的實施中的監督!再次感謝 - 我會在最短的時間之後很快接受答案!也要感謝等比較器的提示! – vikram17000