【问题标题】:TableViewController presented modally does not scrolls to bottom模态显示的 TableViewController 不会滚动到底部
【发布时间】:2016-07-08 23:15:03
【问题描述】:

我目前有一个 CollectionViewController,通过单击单元格将显示详细视图控制器 (TableViewController)。

模态显示 TableVC 的代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *detailVC = [storyboard instantiateViewControllerWithIdentifier:@"DetailTimetableViewController"];

[self presentViewController:detailVC animated:true completion:nil];

上面的代码一切正常,表格视图控制器以模态方式呈现,并且滚动行为正常。

但是,我遵循了本教程 (http://blog.matthewcheok.com/design-teardown-preview-expanding-cells/),它创建了一个自定义 UIViewControllerAnimatedTransitioning,本教程中的所有内容都可以正常工作。

模态显示 TableVC 的代码(带有自定义动画):

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *detailVC = [storyboard instantiateViewControllerWithIdentifier:@"DetailTimetableViewController"];

ExpandingCellTransition *transition = [[ExpandingCellTransition alloc]init];
detailVC.transitioningDelegate = transition;

[self presentViewController:detailVC animated:true completion:nil];

但是,除了 TableViewController 出现时,一切正常,它不允许滚动到底部,并且被限制在特定高度。

我已经尝试搜索类似的问题(TableViewController 无法滚动到底部),并尝试应用他们的解决方案,但都不起作用,我相信问题的原因来自自定义转换委托。

【问题讨论】:

标签: ios xcode tableview presentviewcontroller


【解决方案1】:

MainViewControllerviewDidLoad方法中,添加如下代码:self.automaticallyAdjustsScrollViewInsets= NO

【讨论】:

  • 尝试在两个视图控制器中实现您的建议,但不起作用,谢谢。
【解决方案2】:
use following code in cellForrowAtindexPath delegate method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}

【讨论】:

  • 我相信问题出在表格视图的高度上,而不是里面的单元格,谢谢。
【解决方案3】:

试试这个

// Obj-C
self.automaticallyAdjustsScrollViewInsets = NO;

// Swift
self.automaticallyAdjustsScrollViewInsets = false

希望能帮到你

【讨论】:

  • 尝试在我的 Table View Controller 的 viewDidLoad 中实现,并尝试在 presentViewController 方法之前在 CollectionViewController 中设置它,还是不行,谢谢。
【解决方案4】:

设置 tableviewProperty tableview.UITableViewAutomaticDimension = YES

【讨论】:

  • 我不确定如何实现您的答案,但经过搜索,我发现它与自动调整单元格大小有关,尽管我认为我的问题是由 Table View 的高度问题引起的,谢谢。
  • 在单元格中使用自动布局并设置答案中提到的属性
猜你喜欢
  • 2013-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-27
相关资源
最近更新 更多