2014-11-25 34 views
2

我在我的自定義UITableViewCell中有UIImageView,UILabel,UIButton。 當我將編輯模式設置爲YES時,整個單元格框架向右移動太多。UITableViewCell contentView框在編輯模式下移動得太多

上下滾動表格似乎可以修復它。

但是,爲什麼會發生,我怎麼才能真正解決它?

+0

「太多」相比有哪些這將解決問題了嗎?相比之下沒有什麼,或者你期望的縮進?如果是後者,你爲什麼期望這個確切的距離;你有沒有調整過這個值? – Andreas 2014-11-25 12:39:56

+0

與正常幀移動相比太多。我甚至不知道如何調整這個值。 – 2014-11-25 12:44:13

回答

2

在您的自定義UITableViewCell中使用layoutSubviews和willTransitionToState。 在你的.h文件中添加int狀態; 在您的m單元格添加

- (void)willTransitionToState:(UITableViewCellStateMask)aState 
    { 
     [super willTransitionToState:aState]; 
     state = aState; 
    } 

還補充一點:

- (void)layoutSubviews 
    { 
    [super layoutSubviews]; 
    self.contentView.frame = CGRectMake(0, 
            self.contentView.frame.origin.y, 
            self.contentView.frame.size.width, 
            self.contentView.frame.size.height); 
      if (self.editing) 
      { 
      switch (state) { 
      case 2: 
      // swipe action -> here you play with how much your content will move 
      self.contentView.frame = CGRectMake(90, 
                self.contentView.frame.origin.y, 
                self.contentView.frame.size.width-90, 
                self.contentView.frame.size.height); 
      break; 
       } 
      } else { 
      NSLog(@"subview not in edit %i",state); 
      self.contentView.frame = CGRectMake(0, 
             self.contentView.frame.origin.y, 
             self.contentView.frame.size.width, 
             self.contentView.frame.size.height); 
      [self setNeedsDisplay]; 
    } 
} 

這應該是足夠的定製縮進。

1

這通常發生是由於細胞的佈局是沒有得到所謂的使用習慣小區設置layoutSubviews幀

相關問題