2013-01-06 31 views
3

編輯UITableView時,圓形紅色按鈕和刪除按鈕與自定義單元格重疊。iOS自定義表格視圖在編輯模式下調整大小

我們如何調整自定義單元格的大小以留出紅色圓形按鈕和刪除按鈕的空間。

+0

你在使用UITableViewCell的子類嗎? – jhilgert00

+0

是的,我正在使用基於UITableViewCell的類。我添加了一些標籤和圖像。 – Naz

回答

4

有了這個代碼,您可以根據如何執行不同的任務,什麼編輯細胞的階段是,我已經大量註釋的代碼,因爲我花了這麼長時間來算出這個對我自己。 (得到混淆)

- (void)willTransitionToState:(UITableViewCellStateMask)state { 

     [super willTransitionToState:state]; 

     if (state == UITableViewCellStateDefaultMask) { 

      NSLog(@"Default"); 
      // When the cell returns to normal (not editing) 
      // Do something... 

     } else if ((state & UITableViewCellStateShowingEditControlMask) && (state & UITableViewCellStateShowingDeleteConfirmationMask)) { 

      NSLog(@"Edit Control + Delete Button"); 
      // When the cell goes from Showing-the-Edit-Control (-) to Showing-the-Edit-Control (-) AND the Delete Button [Delete] 
      // !!! It's important to have this BEFORE just showing the Edit Control because the edit control applies to both cases.!!! 
      // Do something... 

     } else if (state & UITableViewCellStateShowingEditControlMask) { 

      NSLog(@"Edit Control Only"); 
      // When the cell goes into edit mode and Shows-the-Edit-Control (-) 
      // Do something... 

     } else if (state == UITableViewCellStateShowingDeleteConfirmationMask) { 

      NSLog(@"Swipe to Delete [Delete] button only"); 
      // When the user swipes a row to delete without using the edit button. 
      // Do something... 
     } 
    } 

你說你添加自定義標籤,什麼不可以,我已經在使用tableviews之前做了同樣的。我通常喜歡正在得到使用動畫塊像重疊到「隱藏」的觀點:

[UIView animateWithDuration:0.3 

         animations:^ { 
          self.myTableCellSubview.alpha = 0.0f; 
         } 
     ]; 

內的每個if語句的上方,並且從1.0F根據狀態改變的α爲0.0f的。

至於一般的壓痕,在屬性檢查器中,確保「縮進編輯時」被選中,您還可以通過編程設置:

cell.shouldIndentWhileEditing = YES; 

如果不工作,你可能在你的自動化過程中會出現一些奇怪的現象。在故事板或xib中,選擇需要縮進的單元格的子視圖,然後轉到大小檢查器(標尺選項卡)。如果子視圖需要從左側(--->)縮進,確保它釘在左邊:

enter image description here

如果子視圖需要從右縮進(< ---) ,確保它釘在合適的:

enter image description here

希望這有助於!

+0

非常好!我用這個函數(void)didTransitionToState:(UITableViewCellStateMask)狀態和(void)setEditing:(BOOL)編輯animated:(BOOL)animate來執行此操作。我看不到大小選項卡中的縮進工具。我不知道爲什麼它沒有顯示我有xcode 4.5.2。 – Naz

1

你可以重寫這些方法之一,我認爲和調整自定義單元格。不知道這正是你基於這個問題提出的問題。

- (void)willTransitionToState:(UITableViewCellStateMask)state 
- (void)didTransitionToState:(UITableViewCellStateMask)state 
+0

你能舉一個簡單的例子來說明如何做到這一點。感謝回覆。 – Naz

相關問題