2012-05-15 81 views
2

我以编程方式创建了UITableView,并发现它不滚动。这是我第一次以编程方式创建UITableView,而不是通过Interface Builder。是否有一些属性,我需要设置编程,使我的视图滚动?我已经尝试setBounces,setScrollEnabled,setAlwaysBounceVertical,但似乎没有工作。任何想法将不胜感激!谢谢!UITableView不滚动(iOS)

示例代码:

UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
CGFloat height = (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) ? 460 : 300; 
feed = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, self.bounds.size.width, height - 44.0f)]; 
[feed setSeparatorColor:[UIColor colorWithRed:38.0f/255.0f green:43.0f/255.0f blue:63.0f/255.0f alpha:1.0f]]; 
[feed setBackgroundColor:[UIColor colorWithRed:48.0f/255.0f green:53.0f/255.0f blue:73.0f/255.0f alpha:1.0f]]; 
[feed setDataSource:self]; 
[feed setDelegate:self]; 
[feed setHidden:YES]; 
[feed setBounces:YES]; 
[feed setScrollEnabled:YES]; 
[feed setAlwaysBounceVertical:YES]; 
[feed setDelaysContentTouches:YES]; 
[self addSubview:feed]; 
+0

你能发表你的代码样本吗? – Matt

+0

添加了代码示例... – user1118042

+0

您的UITableView中是否有足够的内容需要滚动? –

回答

1

尝试设置上的TableView delaysContentTouches。

+0

我添加了setDelaysContentTouches:是我的代码,它什么都没做...... – user1118042

0

ScrollViews必须设置其contentSize才能滚动。尝试设置您的contentSize:

[feed setContentSize:[feed frame].size]; 
+0

当然,这并不适用于表视图。 – Darren

+0

TableView是ScrollView的子类。 – Steve

+0

我认为Darren在说,tableview的内容大小是通过heightForRowAtIndexPath,numberOfRowsInSection,表头大小,节头,页脚视图等隐式设置的。contentSize是内容的大小,而不是“可见”在feed.frame.size – Matt

0

我试图把这个评论,但它是太长了......

你的大多数set方法只是设置的默认值,因此他们没有必要你的代码的最终版本。此外,创建tableview并将其添加为子视图的方式没有任何问题。这导致我相信这个bug是在周围的代码中,可能与superview上的属性有关。当你说“完美地工作”时,你的意思是说你可以选择单元格并让你的didSelectRow ...方法被调用?你可以尝试评论事情,剥离tableview到所需的裸骨头(init,addSubview,numberOfRows返回0,cellForRow返回nil,不要设置委托和数据源以外的任何东西)。这应该给你一个空的tableview,即使没有任何东西,它也可以滚动和跳动。

+0

绝妙的想法,我会给这个镜头 – user1118042

0

我使用启动iOS模拟器的Xamarin Studio。我不得不重新启动我的Mac。现在tableview再次滚动。只重新启动Xamarin或iOS模拟器没有奏效。