Ios 禁用模态视图控制器后,uitable view滚动到底部问题

Ios 禁用模态视图控制器后,uitable view滚动到底部问题,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我的表视图滚动到底部时出现问题。我试图搜索堆栈溢出以找到解决方案,但没有任何帮助 以下是我所拥有的: 我有一个表视图,每次用户滚动到它的底部时,我都会向其中加载额外的单元格。我是这样做的: - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row ==

我的表视图滚动到底部时出现问题。我试图搜索堆栈溢出以找到解决方案,但没有任何帮助

以下是我所拥有的: 我有一个表视图,每次用户滚动到它的底部时,我都会向其中加载额外的单元格。我是这样做的:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == ([self.tableView numberOfRowsInSection:0] - 1))
        //load more data..
}
通过internet连接成功加载数据后,我将调用
[self.tableView reloadData]
刷新表并增加其大小

现在问题来了: 当用户选择单元格时,将显示详细信息视图控制器。我注意到,在显示details视图之前,表的大小会快速调整到原来的大小,只显示内部的初始单元格数

当详细信息视图被取消时,表视图将恢复到其原始大小(不适合加载在
willDisplayCell:forRowAtIndexPath:
)上的数据),并且在所有数据结束之前无法向下滚动

我检查了所有这些点,但没有任何帮助:

  • 通过调用
    视图中的
    [self.tableView reloadData]
    将重新加载表视图中的数据
  • 表视图的
    委托
    数据源
    已正确设置为容器视图控制器
  • 选中当视图再次出现时调用
    tableView:numberOfRowsInSection:
    ,它返回的是我拥有的所有数据的确切数量,但问题在于表的大小不适合我的总数据
我还尝试按如下方式调整表框的大小:

CGRect frame = self.tableView.frame;
frame.size.height = self.tableView.contentSize.height;
self.tableView.frame = frame;
但一切都没有改变

有什么帮助吗

更新: 我在
didSelectRowAtIndexPath
中没有做任何异常操作。代码很简单:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailsViewController *vc=[[DetailsViewController alloc]initWithNibName:@"DetailsViewController" bundle:nil];
    [self presentViewController:vc animated:YES completion:nil];
}
  • 在uiview中获取uiscrollview的对象
  • 在uiscrollview中获取uitableview的对象
  • 设置uitableview的属性scrollenabled=flase
  • 编写uiscrollview的委托方法

    - (void) scrollViewDidScroll:(UIScrollView *)scrollView 
    {
            if (scrollView == scrollObj)  {
                    CGFloat scrollPosition = scrollObj.contentSize.height - scrollObj.frame.size.height - scrollObj.contentOffset.y;
                    if (scrollPosition < 30) {
                            if ((!spinnerBottom.isAnimating) || intGetDataCallRunning == 0) {
                                    //[spinnerBottom startAnimating];
                                    //[self getLoginFollowingUserVideosCall];
                                    //run WebService call and after that reload the table or if you have data exists then only reload the table
                                    //and after reloading table follow step no 5.
                            }
                    }
            }
    }
    

  • didselectRowForcellaIndeXPath:
    如果您正在做一些不寻常的事情,那么发布代码。您的意思是我应该将表格放在滚动视图中??是的,在滚动视图中添加表格。第三步非常重要,我尝试了上面的修复,但不幸的是,我没有在表上显示任何数据!此外,不建议您将表视图放置在滚动视图中,如回答中所述:我最终通过执行以下步骤解决了问题:1-将tableView.contentSize设置为ViewWillDisplay上以前保存的值。2-将滚动位置设置为先前在视图上保存的值将出现。3-调用[tableView setNeedsDisplay]4-调用[tableView reloadData]
    tblVideo.frame = CGRectMake(0, 0, 320, tblVideo.contentSize.height);
    scrollObj.contentSize = CGSizeMake(320,tblVideo.contentSize.height+60);