【问题标题】:Dismissing a viewcontroller messes up the content of UIScrollView关闭视图控制器会弄乱 UIScrollView 的内容
【发布时间】:2013-02-17 04:28:49
【问题描述】:

我有 FirstViewController,它包含一个带有 UIScrollView 的 UIView,并且 UIScrollView 中有一个 UITableView。 UITableView 已禁用滚动,我只增加 UIScrollView 的 contentSize 才能看到完整的 UITableView。

___________________________________
|                                 |
|                                 |
|                                 |
-----------Various content---------
|                                 |
|                                 |
|                                 |
___________________________________
|                                 |
|                                 |
|                                 |
|                                 |
|           UITableView           |
|                                 |
|                                 |
|                                 |
|_________________________________|

当我在我的 UIScrollView 中的某个点上,以便 contentOffset =/= 0 并且我按下 UITableView 中的一个单元格时,我会模态地呈现一个新控制器 (SecondViewController)。这工作正常。当我关闭 SecondViewController 时,FirstViewController 中的内容就搞砸了。

UITableView 最初设置为使其原点位于屏幕中间(垂直)。当我关闭 SecondViewController 时,UITableView 确定它的来源位于屏幕中间,但 UITableView 上方的内容在 UIScrollVIew 中被向上推,其值为 contentOffset(在推入 SecondViewController 之前是什么)。

___________________________________
|                                 |
-----------Various content---------
|                                 |    
|                                 |
|                                 |
|                                 |    
|                                 |
___________________________________
|                                 |
|                                 |
|                                 |
|                                 |
|           UITableView           |
|                                 |
|                                 |
|                                 |
|_________________________________|

编辑:我刚刚发现 UIScrollView 中的 _startOffsetY 已更改。而且我不知道这是否与它有关,但分页已禁用。

【问题讨论】:

    标签: xcode uitableview uiview uiscrollview scroll


    【解决方案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))];
    
    }
    

    【讨论】:

      【解决方案2】:

      确保您使用的是 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];
      }
      

      希望你会喜欢这个............

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-05
        • 1970-01-01
        • 2011-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-06
        相关资源
        最近更新 更多