2014-04-09 53 views
0

我面臨的一個小問題,EM敲我的頭是不能夠解決它......的UITableViewCell重複的UIView

我有一個UITableView定製UITableViewCell ..細胞的高度上文字的大小確定。當用戶點擊它時,文本會被翻譯,並且翻譯後的文本會被添加到新行中。爲使他們看起來分開,我寬度增加UIView lineView不亞於細胞的標籤和height = 1

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(bubbleFrame.origin.x, bubbleFrame.origin.y + bubbleFrame.size.height/2, bubbleFrame.size.width, 1)]; 
        lineView.backgroundColor = [UIColor whiteColor]; 
        lineView.tag = indexPath.row; 
        [cell addSubview:lineView]; 

一切工作正常,但是當我返回到該viewController我看到lineView錯位的每個細胞..

無法理解爲什麼它這樣做..

任何幫助,將不勝感激..在此先感謝.. Image

+0

如何設置單元的新高度?你能顯示heightForRowAtIndexPath方法嗎? – streem

+0

在cellForRow中添加它之前刪除了這個UIView:Atindex? –

+0

你可以顯示'cellForRowAtIndexPath:'方法嗎? – Akhilrajtr

回答

0

經過一番W¯¯好穆斯塔法·易卜拉欣的諮詢工作會有的,我發現了另一個問題,即有similar problem ...所以感謝intropedro的回答的問題解決了:)

加入這個與dequeueReusableCellWithIdentifier

 if (cell == nil) { 
      cell = [[ChatCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } 
     else{ 
      [[cell.contentView viewWithTag:500] removeFromSuperview]; 
     } 

,並改變了我的lineView碼有點太..

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(bubbleFrame.origin.x, bubbleFrame.origin.y + bubbleFrame.size.height/2, bubbleFrame.size.width, 1)]; 
        lineView.backgroundColor = [UIColor whiteColor]; 
        lineView.tag = indexPath.row; 
        [cell addSubview:lineView];