2015-08-08 119 views
1

我有UITableView和UITextfields作爲contentView中的子視圖。當鍵盤處於活動狀態時,UITableView向上移動

他們工作和所有,但是當我選擇底部的,他們正在被鍵盤覆蓋,所以我想UITableView向上滾動。

這裏是我當前的代碼:

-(void)keyboardWillShow:(NSNotification*)notification { 
NSValue *keyboardFrameValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]; 
CGRect keyboardFrame = [[self view] convertRect:[keyboardFrameValue CGRectValue] fromView:nil]; 

[UIView animateWithDuration:0.3 animations:^{ 
    [constraint setConstant:keyboardFrame.size.height]; 
    [self.myTableView layoutIfNeeded]; 
}]; 
} 

-(void)keyboardWillHide:(NSNotification *)notification { 
[UIView animateWithDuration:0.3 animations:^{ 
    [constraint setConstant:0]; 
    [self.myTableView layoutIfNeeded]; 
}]; 
} 

這裏的問題是,它攪亂數據,文本框被添加到了錯誤的細胞和東西。

希望任何人都可以幫忙。

+0

你爲什麼不使用第三方庫? –

+0

爲什麼? uitableview? –

+0

你可以檢查這..... ..... https://github.com/hackiftekhar/IQKeyboardManager或這.... https://github.com/michaeltyson/TPKeyboardAvoiding –

回答

相關問題