2013-07-04 68 views
1

我在Storyboard中創建了UIViewController,並將tableview添加爲Subview。它的工作正常。在那tableview我增加了細胞編程方式,每個單元格包含UITextFieldsUITextViewUITextFields工作正常。但UITextViews有一些麻煩。 EX:當我向UITextView添加文本時,下面的UITextViews重疊。這是爲什麼 ?我試圖整理一整天。但我仍然不能。 :(將文本添加到UITextView時重疊UITextView

case cellResponseNote: 
     cell = [tableView.tableView dequeueReusableCellWithIdentifier:CellIdentifierResponseNote]; 

     if (!cell) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierResponseNote]; 
      cell.frame = CGRectMake(0, 0, cell.frame.size.width, cellNotesHeight); 
      //cell.frame = CGRectMake(0, 0, cell.frame.size.width, cellNotesHeight); 
      if (!self.txtVwResponseNote) { 
       // self.txtVwResponseNote = [[UITextView alloc] initWithFrame:cell.frame]; 
       self.txtVwResponseNote = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cellNotesHeight)]; 
       [self.txtVwResponseNote setScrollEnabled:NO]; 
       [self.txtVwResponseNote setAutoresizingMask:UIViewAutoresizingNone]; 
       [self.txtVwResponseNote setDelegate:self]; 

       [self.txtVwResponseNote setFont:[UIFont systemFontOfSize:14]]; 
       [self.txtVwResponseNote setInputAccessoryView:self.keyboardToolbar]; 
       [self setupMailData:indexPath.row]; 
      } 
     } 
     self.txtVwResponseNote.editable = !(self.isMailForReview); 
     // [cell.contentView addSubview:self.txtVwResponseNote]; 
     [cell addSubview:self.txtVwResponseNote]; 
     contentSubview = self.txtVwResponseNote; 

enter image description here

在此圖像底部可以看到三個單元格。(婁頁腳)當我頂級文本視圖中添加文本值。然後重疊下一個文本視圖。 貝婁的圖像,你可以只看到兩個textviews。底部文本視圖沒有顯示。

enter image description here

那麼,應該怎麼辦?

回答

0

首先作爲一個答案嘗試通過以下方法設置單元格的高度。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    case cellResponseNote: 
     return cellNotesHeight; 
    default: 
     return defaultHeight; 
} 

另外我建議你不要共享textview屬性。請嘗試修改你的代碼,看看你的代碼是否有效。

case cellResponseNote: 
    cell = [tableView.tableView dequeueReusableCellWithIdentifier:CellIdentifierResponseNote]; 
    UITextView *txtVwResponseNote = nil; 
    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierResponseNote]; 
     cell.frame = CGRectMake(0, 0, cell.frame.size.width, cellNotesHeight); 
     //cell.frame = CGRectMake(0, 0, cell.frame.size.width, cellNotesHeight); 
     //if (!self.txtVwResponseNote) { 
      // self.txtVwResponseNote = [[UITextView alloc] initWithFrame:cell.frame]; 
      txtVwResponseNote = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cellNotesHeight)]; 
      [txtVwResponseNote setScrollEnabled:NO]; 
      [txtVwResponseNote setAutoresizingMask:UIViewAutoresizingNone]; 
      [txtVwResponseNote setDelegate:self]; 

      [txtVwResponseNote setFont:[UIFont systemFontOfSize:14]]; 
      [txtVwResponseNote setInputAccessoryView:self.keyboardToolbar]; 
      [txtVwResponseNote setTag:100]; 
     //} 
    } else { 
     txtVwResponseNote = (UITextView *)[cell viewWithTag:100] 
    } 

    [self setupMailData:indexPath.row]; 
    txtVwResponseNote.editable = !(self.isMailForReview); 
    // [cell.contentView addSubview:txtVwResponseNote]; 
    [cell addSubview:self.txtVwResponseNote]; 
    contentSubview = self.txtVwResponseNote; 
0

由於您將其作爲子視圖添加到單元中,然後重新使用該單元,因此重複該操作。將它作爲單元的附屬視圖添加,並將其設置爲零以便不需要它的單元格。

cell.accessoryView = self.txtVwResponseNote; 

而在所有其他單元格中,將accessoryView設置爲nil。

cell.accessoryView = nil;