Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 键盘出现时向上滚动tableview行_Ios_Objective C_Uitableview_Uikeyboard - Fatal编程技术网

Ios 键盘出现时向上滚动tableview行

Ios 键盘出现时向上滚动tableview行,ios,objective-c,uitableview,uikeyboard,Ios,Objective C,Uitableview,Uikeyboard,我的应用当键盘出现时,一些ui组件会从底部隐藏,事实上,这是tableView的最后一行 我正在使用NSNotificationCenter通知键盘出现和消失的时间 这是我的密码: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardOnScreen:) name:UIKeyboardDidShowNotification object:nil]; 但是,tableview向上滚动

我的应用当键盘出现时,一些ui组件会从底部隐藏,事实上,这是tableView的最后一行

我正在使用
NSNotificationCenter
通知键盘出现和消失的时间

这是我的密码:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardOnScreen:) name:UIKeyboardDidShowNotification object:nil];

但是,tableview向上滚动,但不在正确的行,即键盘上方的最后一行。 有时,它会滚动到最后一行隐藏最后一行,或更高。
它与scrollPt值有关

使用此方法键盘出现

- (void)keyboardWasShown:(NSNotification *)aNotification {
        NSDictionary* info = [aNotification userInfo];
        CGSize Size = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

        UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, Size.height - HeightOfToolbar, 0.0);//Set height according to key board height
        self.tableView.contentInset = contentInsets;
        self.tableView.scrollIndicatorInsets = contentInsets;
        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        }
隐藏键盘

 - (void)keyboardWasHidden:(NSNotification *)aNotification
    {

    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;
    }

如果您觉得合适,请使用
tpkeyboardavoidingscrollview
lib。@vaibhav这么难吗。。我应该使用tpkeyboardavoidingscrollview??在我之前的评论中,我没有提到任何困难的词。如果您将tableview控制器与单元格一起使用,上面的一个将默认行为。@Vinodh将尝试您的建议:)每次我关闭键盘时,在执行keyboardWasHidden之后,KeyboardWasShow被调用!!您是否使用了滚动委托方法?是。。scrollViewDidScroll和scrollViewDidScrollToTopi已处理KeyboardWasShow方法在keyboardWasHidden之后的调用。您能告诉我,为什么表格行在表格中向上滚动,然后向下滚动到最后一行!!此方法在ScrollPosition:您可以管理ScrollPosition顶行或底行
 - (void)keyboardWasHidden:(NSNotification *)aNotification
    {

    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;
    }