Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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 UITableView与UITextView滚动问题_Ios_Xcode_Ipad_Uitableview - Fatal编程技术网

Ios UITableView与UITextView滚动问题

Ios UITableView与UITextView滚动问题,ios,xcode,ipad,uitableview,Ios,Xcode,Ipad,Uitableview,我用一些自定义单元格组成了一个tableview。一些自定义单元格包含UIWebView,一些有UISlider加UITextField,一些有UIButton 现在,当我单击位于UITableView底部的uitableviewcell子视图textfield时,我无法使我的表格单元格在键盘上方正确可见。 我不可能使用UITableViewController而不是UIViewController。因为我的UI结构有些怪异和动态。简单地说,这就像 UIView -> UIScrollVi

我用一些自定义单元格组成了一个tableview。一些自定义单元格包含
UIWebView
,一些有
UISlider
UITextField
,一些有
UIButton

现在,当我单击位于
UITableView
底部的uitableviewcell子视图textfield时,我无法使我的表格单元格在键盘上方正确可见。

我不可能使用
UITableViewController
而不是
UIViewController
。因为我的UI结构有些怪异和动态。简单地说,这就像

UIView -> UIScrollView with paging -> x number of UITableViews -> y number of UITableViewCell ->  z number of UITextFields, UISliders, UIWebViews, UIButtons, UILables, etc.
我还尝试了下面的代码使其工作

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
    [table_Question[pageNumber] scrollToRowAtIndexPath:[table_Question[pageNumber] indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
但它不起作用:(

谢谢

编辑1:


我已经检查了textfield、tableviewcell和tableview的引用。因此对象的引用不是问题。

根据我的理解,当用户开始编辑
UITableViewCell
内的
UITextField
时,您希望显示
UITextField
以及键盘。 如果是这种情况,您可以将
UITableView
contentInset
设置为所需的大小,然后滚动到所需的索引路径

以下是示例代码:
根据我的理解,当用户开始在
UITableViewCell
内编辑
UITextField
时,您希望显示
UITextField
以及键盘。 如果是这种情况,您可以将
UITableView
contentInset
设置为所需的大小,然后滚动到所需的索引路径

以下是示例代码: 试试这个代码

- (void)textFieldDidBeginEditing:(UITextField *)textField
{

    UITableViewCell *aCell = [table_Question[pageNumber] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
    CGSize cellSize = aCell.frame.size;
    [table_Question[pageNumber] setContentOffset:CGPointMake(0, cellSize.height*2) animated:YES];
}
试试这个代码

- (void)textFieldDidBeginEditing:(UITextField *)textField
{

    UITableViewCell *aCell = [table_Question[pageNumber] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
    CGSize cellSize = aCell.frame.size;
    [table_Question[pageNumber] setContentOffset:CGPointMake(0, cellSize.height*2) animated:YES];
}
请尝试此代码

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
        UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
        NSIndexPath *indexPath = [[table_Question[pageNumber] indexPathForCell:cell];

        int totalRows = 0;
        if([[table_Question[pageNumber] numberOfSections] > 1)
         {
              for(int i = 0; i<([indexPath.section] - 1);i++)
               {
                     totalRows += [[table_Question[pageNumber] numberOfRowsInSection:i];
                }
          }

          totalRows += indexPath.row;

        int  yPosition = totalRows * cell.frame.size.height;
        CGPoint offset = CGPointMake(0, yPosition);
        [[table_Question[pageNumber] setContentOffset:offset animated:YES];
}
-(void)textFieldDidBeginEditing:(UITextField*)textField
{
UITableViewCell*单元格=(UITableViewCell*)[[textField superview]superview];
NSIndexPath*indexPath=[[table_Question[pageNumber]indexPathForCell:cell];
int totalRows=0;
如果([[表格问题[页码]章节编号]>1)
{
对于(inti=0;i请尝试以下代码

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
        UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
        NSIndexPath *indexPath = [[table_Question[pageNumber] indexPathForCell:cell];

        int totalRows = 0;
        if([[table_Question[pageNumber] numberOfSections] > 1)
         {
              for(int i = 0; i<([indexPath.section] - 1);i++)
               {
                     totalRows += [[table_Question[pageNumber] numberOfRowsInSection:i];
                }
          }

          totalRows += indexPath.row;

        int  yPosition = totalRows * cell.frame.size.height;
        CGPoint offset = CGPointMake(0, yPosition);
        [[table_Question[pageNumber] setContentOffset:offset animated:YES];
}
-(void)textFieldDidBeginEditing:(UITextField*)textField
{
UITableViewCell*单元格=(UITableViewCell*)[[textField superview]superview];
NSIndexPath*indexPath=[[table_Question[pageNumber]indexPathForCell:cell];
int totalRows=0;
如果([[表格问题[页码]章节编号]>1)
{

对于(int i=0;i)当键盘可见时,您为什么不调整整个UIView的大小?textFieldDidBeginEditing:()方法是否正在启动?@Lefteris:那么我必须调整其中所有内容的大小,我认为这不是个好主意。@BhanuPrakash:当然它正在启动。@CrimeMasterGOGO但您使用的是UITableView(将其嵌套在scrollview中并不重要)。因此,调整UITableView的大小实际上并不要求您做任何事情。它只会按照您的意愿向上移动单元格……当键盘可见时,为什么不调整整个UIView的大小?TextFieldDiBeginEdit:()方法是否正在启动?@Lefteris:那么我必须调整其中的所有内容,我认为这不是个好主意。@BhanuPrakash:是的,当然它正在启动。@CrimeMasterGOGO但您使用的是一个UITableView(将它嵌套在滚动视图中并不重要)。因此,调整UITableView的大小实际上并不要求您做任何事情。它只会按照您的意愿向上移动单元格…tableview的位置在哪里。如果它位于屏幕底部或键盘覆盖其视图的某个位置,则您必须增加“contentSize”将此项添加到文本字段shouldBeginediting CGPoint scrollPoint=CGPointMake(0,所需高度);[your_scrollview setContentOffset:scrollPoint animated:YES];'tableview的位置在哪里。如果它位于屏幕底部或键盘覆盖其视图的某个位置,则必须增加滚动视图的“contentSize”。将其添加到文本字段shouldBeginediting CGPoint scrollPoint=CGPointMake(0,所需高度);[滚动视图设置ContentOffset:scrollPoint动画:是];'