2014-06-20 30 views
0

我更新。 我發現一個關於UITableview的奇怪問題。ios7 UITableView高度,已更改,但返回默認

當UITableView的加載,高度爲400 ,然後,在程序中,我改變的UITableView的高度

CGRect talkListFrame = _talkList.frame; 
talkListFrame.size.height = _talkListOriginalHeight -keyboardSize.height; 
[_talkList setFrame:talkListFrame]; 

這是很好的,我改變了的UITableView(talkList)的高度。 但是,當我把數據的uitableview,uitableview的高度返回到400. ※我使用了一個自定義的uitableviewcell,只是在單元格中放置一個標籤。

UILabel *lable = (UILabel*)[cell viewWithTag:6]; 
lable.text [email protected]"xxxx"; 

如果我不使用自定義uitablecell,那很好,高度不會返回。

cell.textLabel.text [email protected]""; 

爲什麼?自定義單元格是問題

+1

看起來你是在談論表的行高度。請讓我知道如果我是對的.. – iCreative

回答

1

當顯示鍵盤時請不要更改frame。更改contentInset

我不喜歡這樣寫道:

- (void)keyboardWillShow:(NSNotification *)notification{ 

    CGRect keyboardFrame = [[[notification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue]; 

    [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState animations:^{ 

     UIEdgeInsets tableViewInsets = UIEdgeInsetsMake(0, 0, keyboardFrame.size.height, 0); 
     _talkList.scrollIndicatorInsets = tableViewInsets; 
     _talkList.contentInset = tableViewInsets; 

    }completion:nil]; 
} 

- (void)keyboardWillHide:(NSNotification *)notification{ 

    [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState animations:^{ 

     UIEdgeInsets tableViewInsets = UIEdgeInsetsZero; 
     _talkList.scrollIndicatorInsets = tableViewInsets; 
     _talkList.contentInset = tableViewInsets; 

    }completion:nil]; 
} 
+0

非常感謝你。我解決了這個問題! – user1870589