簡體   English   中英

切換UITableView時,子視圖將無法正確隱藏在自定義UITableViewCell中

[英]Subview won't hide correctly in custom UITableViewCell on toggling of UITableView edit

因此,我的應用程序在其左漢堡包地下室中具有可編輯且可排序的UITableView:

可編輯的UITableView

為了確保表格單元格足夠薄,可以在編輯時同時顯示刪除按鈕和排序拖動手柄,我創建了一個自定義UITableViewCell來處理表格單元格的編輯:

UITableView編輯

一切在編輯時都可以正常工作,但是當我點擊完成時,而不是隱藏“刪除”按鈕就會出現問題:

UITableView完成

在BookmarkTableViewCell.m中,此代碼為:

- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
  [super setEditing:editing animated:animate];

  if (editing) {
    for (UIView * view in self.subviews) {
        if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
        {
            UIView *movedReorderControl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
            [movedReorderControl addSubview:view];
            [self addSubview:movedReorderControl];
            CGRect newFrame = movedReorderControl.frame;
            newFrame.origin.x = -35;
            movedReorderControl.frame = newFrame;
        }
    }
    UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 24, 24)];
    [deleteBtn setImage:[UIImage imageNamed:@"icon_delete.png"]];
    [self addSubview:deleteBtn];
  }
}

讓我知道您是否需要更多詳細信息。 解決此問題的任何見解都將是很棒的。 謝謝!

看起來您正在添加deleteBtn,但並未刪除它。 如果編輯為假,則應找到deleteBtn單元格並將其從其超級視圖中刪除,以使其消失。

暫無
暫無

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

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