【问题标题】:UITableView in UIPageViewController not call method didSelectRowAtIndexPathUIPageViewController 中的 UITableView 不调用方法 didSelectRowAtIndexPath
【发布时间】:2016-11-18 13:41:37
【问题描述】:

containerViewController | V pageViewController | | V V ViewController1 ViewController2 | V tableView (property of ViewController2)

你好,

我有一个带有两个 UIViewController 的 pageViewController。其中一个包含一个 tableView。 在此 pageViewController 中创建我的 tableView 时,从未触发过方法 didSelectRowAtIndexPath。但是,我可以处理单元格中的“触摸事件”。

看下面的代码:

// Init pageViewController
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

self.pageController.view.translatesAutoresizingMaskIntoConstraints = false;

CGRect pageFrame = self.view.bounds;
pageFrame.origin.y = TOP_BAR_HEIGHT;
self.pageController.view.frame = pageFrame;

// Set pageviewControllers with my array of controllers (with ViewController1 and ViewController2)
[self.pageController setViewControllers:@[self.subViewControllers[0]]
                              direction:UIPageViewControllerNavigationDirectionForward
                               animated:NO
                             completion:nil];

[self addChildViewController:self.pageController];
[self.view addSubview:self.pageController.view];
[self.pageController didMoveToParentViewController:self];

但是,非常奇怪的是:当我用手指拖动单元格并移开手指时,触发了方法 didSelect,而简单的触摸不起作用...

我已经在 Stackoverflow 上搜索过,我只找到了这个topic

他用 UIViewController 中的嵌入式 tableView 解决了他的问题,但我已经实现了这样的代码......

编辑:我已将代码放在 Github 上。 source code

【问题讨论】:

  • table view的delegate和数据源是什么对象?
  • 委托是 ViewController2,数据源也是如此。但是直接用tableView没有问题(在其他情况下效果很好)
  • 你是否实现了 didDEselect 方法?我有一次,搜索了几个小时。
  • DidDeselect 没有实现...但是当我把它放在另一个控制器中时,tableView 工作得很好(tableView 在应用程序的不同位置使用)

标签: ios objective-c uitableview uipageviewcontroller


【解决方案1】:

好的,我找到了问题... 容器视图上有一个 UITapGestureRecognizer。那是错误。 谢谢大家。

【讨论】:

  • 我也面临同样的问题。您能否解释一下 UITapGestureRecognizer 的问题以及您是如何解决的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-29
  • 1970-01-01
  • 2012-09-18
相关资源
最近更新 更多