2011-06-10 96 views
0

我想使用UITableViewController並用自定義視圖替換編輯模式按鈕(通常默認爲'刪除')。editingAccessoryView沒有出現?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ... (other code) ... 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.tag = pd.itemId; 
    UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"]; 
    cell.editingAccessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease]; 
    //cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease]; 
    return cell; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return NO; 
} 

當我嘗試刷卡時,沒有任何反應。奇怪的是,如果我取消註釋cell.accessoryView行,我的圖像顯示正常。這使我認爲它是錯誤的編輯設置的東西?但無論在線還是在文檔中,我都可以找到這些設置應該是什麼。

謝謝!

更新:啊。好的,所以我給了我一個UITableView導航控制器的'編輯'按鈕。現在我可以將所有單元切換到編輯模式,並顯示我的配件。那麼「刷」一個細胞呢?如果你設置了editingAccessoryView,並希望它出現

庫爾特

回答

0
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

canEditRowAtIndexPath應該返回YES。當表格未處於編輯模式時,可以看到簡單的accessoryView。然而,電池的揮動顯示刪除確認按鈕,這是不editingAccessoryView,並用

- (void)willTransitionToState:(UITableViewCellStateMask)state; 

搞亂而不調用[超級willTransitionToState:狀態]。會導致意外的行爲(你的單元格不會離開UITableViewCellStateShowingDeleteConfirmationMask狀態)。如果您可以管理超級通話並且不允許該單元顯示刪除確認按鈕,那麼您就完成了。

+0

將否更改爲yes未啓用滑動。你是說我必須繼承UITableViewCell並覆蓋willTransitionToState?這似乎應該是不必要的,因爲我使用的是UITableViewCell的標準字段。 – 2011-06-10 15:45:14

+0

我還打算加入,我讀了willTransitionToState的文檔,它似乎表明'show delete button state'與'editing'狀態不同。有人可以詳細說明嗎?我認爲顯示刪除按鈕只是標準的編輯狀態。 – 2011-06-10 15:46:46

+0

試試tableView.editing = YES;看到真正的編輯狀態(左邊刪除圓形按鈕,通常右邊的控制權重新排序),滑動是不同的...... – tsakoyan 2011-06-10 15:51:12