English 中文(简体)
可上诉的意见转录,但不能适当投递
原标题:UITableView resizing but not scrolling properly

I have this code, which resizes the tableview when I click a textfield inside of a cell so that the keyboard doesn t overlap the bottom row. The problem is, after it resizes, it scrolls to the top of the table instead of the cell that I had clicked the textfield in.

- (void)keyboardDidShow:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect frame = CGRectMake(self.vitalsTableView.frame.origin.x, 
                              self.vitalsTableView.frame.origin.y, 
                              self.vitalsTableView.frame.size.width, 
                              self.vitalsTableView.frame.size.height - size.height);
    self.vitalsTableView.frame = frame;

    VitalsTableViewCell *cell = (VitalsTableViewCell*)[self.selectedTextField superview];
    [self.vitalsTableView scrollRectToVisible:cell.frame animated:YES];
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    self.vitalsTableView.frame = CGRectMake(self.vitalsTableView.frame.origin.x, 
                                      self.vitalsTableView.frame.origin.y, 
                                      self.vitalsTableView.frame.size.width, 
                                      self.vitalsTableView.frame.size.height + size.height);
}

- (void) textFieldDidBeginEditing:(UITextField *)textField {
    self.selectedTextField = textField;
//    [self scrollToRectOfTextField];
    NSIndexPath *path = [self.vitalsTableView indexPathForSelectedRow];
    [self.vitalsTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

- (void)scrollToRectOfTextField {
    VitalsTableViewCell *cell = (VitalsTableViewCell*)[self.selectedTextField superview];
    CGRect r = CGRectMake(self.selectedTextField.frame.origin.x, 
                          cell.frame.origin.y+self.selectedTextField.frame.origin.y,
                          self.selectedTextField.frame.size.width,
                          self.selectedTextField.frame.size.height);
    [self.vitalsTableView scrollRectToVisible:r animated:YES];
    NSIndexPath *path = [self.vitalsTableView indexPathForSelectedRow];
    [self.vitalsTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
最佳回答

当你改变表象框架时,它要求所有必要的方法加以重新编排,并抄录表概览中排在首位的<代码>contentOffset。 每当您改变这个框架时,你们都必须向您所希望的<编码>CGPoint或发送。 因此,首先,除了你想要发展点外,然后重新调整框架,然后与新框架相比向点倾斜。

我在你的法典中看到,你正在开车,但这是错开的。

- (void)scrollToRectOfTextField {
    VitalsTableViewCell *cell = (VitalsTableViewCell*)[self.selectedTextField superview];
    CGRect r = CGRectMake(self.selectedTextField.frame.origin.x, 
                          cell.frame.origin.y+self.selectedTextField.frame.origin.y,
                          self.selectedTextField.frame.size.width,
                          self.selectedTextField.frame.size.height);
    [self.vitalsTableView scrollRectToVisible:r animated:YES];
    NSIndexPath *path = [self.vitalsTableView indexPathForSelectedRow];
    [self.vitalsTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

首先,我走了最后两条线,一行走进指数道路。 第二,如果你审查<代码>r.origin 或许,你可以找到一个点(0,0),因为案文实地框架的起源与其表面观点相对,而不是表格。 可以通过使用<代码>convertRect:toView:来说明案文领域与表格观点的相对之处。 文件here

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签