Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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中关闭UIImageView后不会立即返回UITableView中的第一行_Ios_Uitableview_Uiimageview_Uitextfield - Fatal编程技术网

控件在iOS中关闭UIImageView后不会立即返回UITableView中的第一行

控件在iOS中关闭UIImageView后不会立即返回UITableView中的第一行,ios,uitableview,uiimageview,uitextfield,Ios,Uitableview,Uiimageview,Uitextfield,我有一个iOS应用程序,其中显示一个UITableView,它又由自定义行组成,自定义行由UITextFields和UILabel组成。在第一次启动时,我有一个UIImageView,它覆盖UITableView,直到用户按下按钮以关闭UIImageView(从而显示它后面的UITableView) 然而,我的问题是,它没有将控制权返回UITableView的第一行,而是选择了UITableView的最后一行,除此之外,尽管我显式调用了该方法,“becomeFirstResponder”,UIT

我有一个iOS应用程序,其中显示一个UITableView,它又由自定义行组成,自定义行由UITextFields和UILabel组成。在第一次启动时,我有一个UIImageView,它覆盖UITableView,直到用户按下按钮以关闭UIImageView(从而显示它后面的UITableView)

然而,我的问题是,它没有将控制权返回UITableView的第一行,而是选择了UITableView的最后一行,除此之外,尽管我显式调用了该方法,“becomeFirstResponder”,UITableView最后一行的UITextField不允许我输入文本,直到我从表中显式选择一行。只有这样,我才能输入文本。我假设我的方法“cellForRowAtIndexPath”自上而下填充我的表,这就是为什么选择表的最后一行,而不是顶部(这是我的猜测,如果我错了,请纠正我)

我想做的是,一旦用户取消UIImageView并使其自动成为“第一响应者”,就启用UITableView的第一行,允许用户立即输入文本,而无需显式选择特定行

按下按钮后关闭UIImageView的代码如下:

- (IBAction)beginDataEntry:(id)sender {
    
    [_imageView removeFromSuperview];
    [_cell.dataField becomeFirstResponder];
    
} 

在我从表中显式选择一行之前,我的UITableView似乎处于“不稳定”状态。我做错了什么?

使用UITableView ScrollToRowatineXpath:atScrollPosition:animated:在重新显示视图时显示正确的行

使用索引路径引用表行总是比保留对单元格的引用更安全。因此,这里有一个替代方案:

- (IBAction)beginTireCountEntry:(id)sender {

    [_imageView removeFromSuperview];
    NSIndexPath firstCellPath = [NSIndexPath indexPathForRow:0 inSection:0];
     [self.tableView scrollToRowAtIndexPath: firstCellPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    MyCell cell = (MyCell *)[self.tableView cellForRowAtIndexPath:firstCellPath];
    [cell.dataField becomeFirstResponder];

} 

您可以添加更多的代码吗,比如如何创建表视图?我在Interface Builder中创建UITableView。