简体   繁体   中英

UITableView Doesn't Scroll (iOS)

I have created a UITableView programmatically and am finding that it does not scroll. This is the first time I've created a UITableView programmatically as opposed to through Interface Builder. Is there some property I need to set programmatically to enable my view to scroll? I have tried setBounces, setScrollEnabled, setAlwaysBounceVertical, but nothing seems to work. Any ideas would be greatly appreciated! Thanks!

Sample Code:

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];

尝试在TableView上设置delaysContentTouches。

ScrollViews must have their contentSize set in order to scroll. Try setting your contentSize:

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

I tried to put this in a comment but it was too long...

Most of your set methods are just setting the defaults, so they aren't necessary in the final version of your code. Also, there is nothing wrong with the way you create the tableview and add it as a subview. This leads me to believe the bug is in surrounding code, maybe having to do with properties on the superview. When you say "working perfectly", do you mean that you can select cells and have your didSelectRow... method called? You can try to comment things out, stripping the tableview to the bare bones required (init, addSubview, numberOfRows return 0, cellForRow return nil, don't set anything other than the delegate and datasource). That should give you an empty tableview that scrolls and bounces even with nothing in it.

I know this is an old thread, but are you seeing this problem in the iOS Simulator by any chance? I was having the same problem with my table view, but it turned out that I just wasn't using the right gesture in the simulator. See Can't get UITableView list to scroll in iPhone simulator .

I'm using Xamarin Studio which starts the iOS Simulator. I had to restart my Mac. Now the tableview scrolls again. Only restarting Xamarin or the iOS Simulator didn't worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM