scrollsToTop无法使用UIViewController包含 [英] scrollsToTop not working with UIViewController containment
问题描述
使用SDK 6.1,Xcode 4.6.1,我制作了一个新项目Master-Detail iOS App,ARC,没有故事板。
Using SDK 6.1, Xcode 4.6.1, I make a new project Master-Detail iOS App, ARC, no storyboards.
然后在 DetailViewController
,在 viewDidLoad
中我添加了两个 UITableView
包含在<$ c中$ c> UIViewController s并确保第二个隐藏如下:
Then in the DetailViewController
, in the viewDidLoad
I add two UITableView
s contained in UIViewController
s and make sure the second one is hidden like this:
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *lViewController1 = [[UIViewController alloc] init];
UITableView *lTableView1 = [[UITableView alloc] initWithFrame: self.view.frame];
lTableView1.scrollsToTop = YES;
[lViewController1.view addSubview: lTableView1];
lTableView1.dataSource = self;
[self.view addSubview: lViewController1.view];
[self addChildViewController: lViewController1];
UIViewController *lViewController2 = [[UIViewController alloc] init];
UITableView *lTableView2 = [[UITableView alloc] initWithFrame: self.view.frame];
lTableView2.scrollsToTop = YES;
[lViewController2.view addSubview: lTableView2];
lTableView2.dataSource = self;
[self.view addSubview: lViewController2.view];
[self addChildViewController: lViewController2];
// now hide the view in view controller 2
lViewController2.view.hidden = YES;
}
(我确保 DetailViewController
是一个数据源,返回100行 UITableViewCell
s, textLabel.text
设置为 @hello
)
(I make sure the DetailViewController
is a datasource that returns 100 rows of UITableViewCell
s with the textLabel.text
set to @"hello"
)
第二个视图控制器的存在使得 scrollsToTop
(点击状态栏)不再起作用。如果我不使用 UIViewController
包含,只需添加两个 UITableView
并设置第二个隐藏, scrollsToTop
确实有效。
The presence of the second view controller makes that scrollsToTop
(tapping on the status bar) does not work anymore. If I do not use UIViewController
containment and just add two UITableView
s and set the second one to be hidden, scrollsToTop
does work.
我做错了什么?
推荐答案
我目前正在试验您的项目。当
I am currently experimenting with your project. When
lViewController2.view.hidden = YES;
替换为
lTableView2.hidden = YES;
然后滚动工作,即使控制器收容也是如此。
then the scrolling works, even with controller containment.
我试图在控制器的视图和表之间插入一个视图,然后隐藏这个视图,但表格没有滚动。
I tried to insert a view between the controller's view and the table and then hide this view, but the table was not scrolling.
我试图隐藏控制器通过试验 shouldAutomaticallyForwardAppearanceMethods
但表格没有滚动。
I tried to hide the controller by experimenting with shouldAutomaticallyForwardAppearanceMethods
but the table was not scrolling.
结果:来自我的实验中,在视图层次结构中只能看到一个滚动视图,并且不会检出父视图的隐藏
属性。 隐藏
必须在所有其他滚动视图上设置为否
,而不是其父视图。
Result: From my experiments, only one scroll view must be visible in the view hierarchy and the hidden
property of the parent views is not checked out. hidden
must be set to NO
on all other scroll views, not their parent views.
这篇关于scrollsToTop无法使用UIViewController包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!