UITableview未正确放置在uiscrollview中
问题描述:
我有一个使用pagecontrol的UIScrollView。我将代码中的表格添加到滚动视图中。 tableviews的每边应该有20px的填充。所以我做了以下。UITableview未正确放置在uiscrollview中
CGRect frame = self.scrollView.bounds;
frame.size.width = 280.0f;
frame.size.height = self.scrollView.bounds.size.height;
frame.origin.x = (320 * page)+20;
NSLog(@"orgin x is %d",(320 * page)+20);
NSLog(@"orgin x is %f",frame.origin.x);
frame.origin.y = 0;
UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
tableStage.backgroundColor = [UIColor colorWithRed:(250/255.0) green:(248/255.0) blue:(247/255.0) alpha:100];
tableStage.delegate = self;
tableStage.dataSource = self;
tableStage.tag = page;
tableStage.contentMode = UIViewContentModeScaleAspectFit;
[self.scrollView addSubview:tableStage];
[self.pageViews replaceObjectAtIndex:page withObject:tableStage];
但我得到以下结果。
就像你可以看到下一个tableview总是移动更多的东西到左边。任何想法如何我可以解决这个问题?
答
试试这个
CGRect frame = self.scrollView.bounds;
float offset=20;
frame.size.width = frame.size.width-(2*offset);
frame.origin.x = (320 * page)+offset;
frame.origin.y = 0;
UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
,不需此行
tableStage.contentMode = UIViewContentModeScaleAspectFit;
答
CGRect frame = self.scrollView.bounds;
frame.size.width = 280.0f;
frame.size.height = self.scrollView.bounds.size.height;
frame.origin.x = (self.scrollView.bounds.size.width * page)+(self.scrollView.bounds.size.width - (frame.size.width/2));
frame.origin.y = 0;
答
如果您正确设置了内容大小以及每个新表格视图的位置,它将完美地工作。也启用了分页。
是什么[self.pageViews replaceObjectAtIndex:页withObject:tableStage]吗?用新表(tableStage)替换当前表? – Amar 2013-05-14 09:40:41