Uitextfield滚动基于Uitableview的索引路径

时间:2015-03-30 06:52:00

标签: ios objective-c iphone uitableview uitextfield

我试图在uitableview中基于indexpath设置文本字段的滚动,为此我已经按照以下方式编写了我的代码

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

- (void)keyboardWillShow:(NSNotification *)sender
{
    CGSize kbSize = [[[sender userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    NSTimeInterval duration = [[[sender userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    [UIView animateWithDuration:duration animations:^
     {
         UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 0, kbSize.height, 0);
         [self.mytableview setContentInset:edgeInsets];
         [self.mytableview setScrollIndicatorInsets:edgeInsets];

     }];
}

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


    NSTimeInterval duration = [[[sender userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    [UIView animateWithDuration:duration animations:^
     {
         UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
         [self.mytableview setContentInset:edgeInsets];
         [self.mytableview setScrollIndicatorInsets:edgeInsets];

         self.mytableview.contentOffset = CGPointMake(0,0);

     }];
}

通过添加所有那些编码,我的文本字段滚动在Iphone 5(Retina 4英寸)设备中工作正常,但它不工作的Iphone 4设备(Retina 3.5英寸)。

注意:我没有使用自动布局,基于storyBoards我正在使用不同的设备。

任何人都可以提供一些有用的信息。在此先感谢

0 个答案:

没有答案