簡體   English   中英

iOS自定義表格視圖單元格在編輯模式下調整大小

[英]iOS custom table view cell resize in edit mode

編輯UITableView ,圓形紅色按鈕和刪除按鈕與自定義單元格重疊。

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

使用此代碼,您可以執行不同的任務,具體取決於編輯單元格的方式和階段。我對代碼進行了大量評論,因為我花了這么長時間來自行解決這個問題。 (變得混亂)

  - (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語句中,並根據狀態將alpha從1.0f更改為0.0f。

對於一般的縮進,在屬性檢查器中,確保選中“編輯時縮進”,您也可以通過以下方式以編程方式設置:

cell.shouldIndentWhileEditing = YES;

如果這不起作用,您可能會在自動調整過程中出現一些奇怪之處。 在故事板或xib中,選擇需要縮進的單元格的子視圖,然后轉到“大小”檢查器(標尺選項卡)。 如果子視圖需要從左側縮進(--->),請確保它固定在左側:

在此輸入圖像描述

如果子視圖需要從右側縮進(<---),請確保它固定在右側:

在此輸入圖像描述

希望這可以幫助!

您可以覆蓋我認為的這些方法之一並調整自定義單元格的大小。 根據這個問題,不確定這正是你所要求的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM