I added tableview to scrollview programmatically but it is not scrolling. While i tried the same using XIB. but it is working fine.

here is my code

CGRect frame = CGRectMake(30, 30.0f, 900, 300.0f);

eappTable = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]  style:UITableViewStylePlain];

eappTable.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

eappTable.delegate = self;

eappTable.dataSource = self;

eappTable.scrollEnabled = YES;

eappTable.scrollsToTop = YES;

[eappTable reloadData];

[scrollView addSubview:eappTable];
有帮助吗?

解决方案

eappTable = [[UITableView alloc] nitWithFrame:YourSize style:Table_Style]];
eappTable.delegate = self;
eappTable.dataSource = self;
eappTable.scrollEnabled = YES;
[scrollView addSubview:eappTable];

And set self.scrollView.contentSize

其他提示

You have to set the Content Size of ScrollView.

Hope it Helps !!!

Try to enable bouncing (because if all cells size are smaller than the uitableview size it self, it won't scroll if bounce is set to NO) :

eappTable.bounces = YES;

[eappTable  setContentSize:CGSizeMake(320, 680)];

I know this is not the answer you are looking for. But I would like to mention one point : Never add tableview as the subview of your scrollview.

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top