我已經使用IB創建了自定義單元格,並將其顯示在tableView
上,但未涵蓋整個窗口。 我設置了一個toolbar
並給了它一個按鈕,用於切換isEditing
屬性和按鈕標題。我也在didSelectRowAtIndexPath
中製作了if(!self.editing)
。使用自定義單元格編輯模式
我收到反饋,當按鈕被擊中時,我處於編輯模式,但我的自定義單元格不顯示左側的刪除標誌。如果我滑動單元格,則出現右邊的刪除按鈕,但是如果我按下該按鈕,則應用程序會崩潰,但稍後我會解決該問題,只是認爲我會這樣說,以防萬一導致您我犯的錯誤。
我讀過,如果我沒有將我的自定義單元格分配給cell.contentview
,cellforRowAtIndexPath
,它可能會發生它不顯示左手刪除標誌。我嘗試了一下,並得到一個錯誤。
這是我第一次用IB製作定製單元格,所以如果我犯了一個愚蠢的錯誤,請和我一起裸露。
在cellForRowAtIndexPath
的代碼,在那裏我指定自定義單元格:
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
// some more setup and stuff
return cell;
感謝您的幫助!
Okkkaaaaay,對不起,那是非常愚蠢的,但它可以發生.. 由於我的視圖控制器是UIViewController的,不是的UITableViewController的子類,我會需要使編輯按鈕切換self.MyTableView.editing .. – Nareille