2012-01-11 81 views
0

我使用IB在Xcode 4中創建了一個UITableViewCell。但是,當我觸發我的編輯按鈕時,出現一些奇怪的原因,cell的行爲真的很奇怪,並沒有與普通表格視圖單元格相同的動畫。我不知道發生了什麼,我嘗試在我的自定義單元類中實現-(void)setEditing:(BOOL)editing animated:(BOOL)animated,但仍然無效。編輯自定義單元格時出現奇怪的動畫?

UPDATE:我的,我現在用的細胞中ViewController,有cellForAtIndex下此代碼,以顯示該單元格。

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if(cell == nil) 
    { 
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil]; 
    for (id currentObject in topLevelObjects) 
    { 
     if ([currentObject isKindOfClass:[UITableViewCell class]]) 
     { 
      cell = (CustomCell *) currentObject; 
      break; 
     } 
     return cell; 
    } 
} 

普通視圖:

The normal view

當攻編輯按鈕:

enter image description here

edit

甚至當刷卡它覆蓋在它應該拋開移動它的文字:

enter image description here

回答

2

首先建議;請勿將IB用於定製UITableViewCell s。

接下來;確保你將任何自定義視圖添加到UITableViewCellcontentView ......不只是單元本身。當顯示編輯部分(如刪除按鈕)時,UITableViewCell的contentView將自動縮小。如果您對UILabel /不管你已經添加到contentView正確UIViewAutoresizing面具,它會得到調整大小/正確地移動。

編輯,回答在評論你的問題:

同樣的方式將任何自定義視圖。你可以自己創建一個類,也可以根據你的需要特別構建它。類通常是最好,所以你可以引用任何的你加入到細胞自定義的東西,再利用細胞/等

但是,這裏的是建設一個特設的一個例子。

UIImageView * myCheckBox = ... 
UILabel * myLabel = ... 
UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; 
[cell.contentView addSubview:myCheckBox]; 
[cell.contentView addSubview:myLabel]; 
self.customCell = cell; 

編輯#2

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    self.textLabel.frame = CGRectMake(50, self.textLabel.frame.origin.y, self.contentView.frame.size.width - 50, self.textLabel.frame.size.height); 
} 
+0

更新的問題,進一步說明這個問題。 – Souljacker 2012-01-11 19:42:33

+0

@ Ravin455 - 我完全理解你的問題。我去過那兒。無需進一步解釋。 – Steve 2012-01-11 19:43:31

+0

如果我必須以編程方式添加它,那麼我應該如何添加它?我唯一的問題是在左側添加複選框UIButton。 – Souljacker 2012-01-11 19:45:24

相關問題