我有一个FirstViewController,其中包含一个带有UIScrollView的UIView,并且UIScrollView中有一个UITableView。 UITableView已禁用滚动,我只增加了UIScrollView的contentSize,以便能够看到完整的UITableView。
___________________________________
| |
| |
| |
-----------Various content---------
| |
| |
| |
___________________________________
| |
| |
| |
| |
| UITableView |
| |
| |
| |
|_________________________________|
当我在UIScrollView中的某个点,以便contentOffset = / = 0并按下UITableView中的单元格时,我会以模态方式呈现一个新的控制器(SecondViewController)。这很好用。当我关闭SecondViewController时,FirstViewController中的内容搞砸了。
UITableView最初设置为将其原点放在屏幕中间(垂直)。当我关闭SecondViewController时,UITableView肯定它的起源位于屏幕中间,但是UITcrollVIew上面的内容在contentOffset中被推高了(在推送SecondViewController之前它是什么)。
___________________________________
| |
-----------Various content---------
| |
| |
| |
| |
| |
___________________________________
| |
| |
| |
| |
| UITableView |
| |
| |
| |
|_________________________________|
编辑:我刚刚发现UIScrollView中的_startOffsetY已更改。而且我不知道这是否与它有关,但是禁用了分页。
答案 0 :(得分:1)
这样做:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[scrollView setContentOffset:CGPointZero];
}
-(void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[scrollView setContentSize:(CGSizeMake(320, scrollSubView.frame.size.height))];
}
答案 1 :(得分:0)
确保您使用的是iOS5模拟器或设备,因为在iOS6中不推荐使用模型viewController。
要在所有iOS中工作,你必须像......一样......
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self presentViewController:test animated:YES completion:nil];
}
else
{
[self presentModalViewController:test animated:YES];
}
并解雇
if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
{
[self dismissViewControllerAnimated:animated completion:nil];
}
else
{
[self dismissModalViewControllerAnimated:animated];
}
希望你会喜欢这个............