viewWillAppear being called twice in iOS5

前端 未结 4 1324
甜味超标
甜味超标 2021-01-06 02:35

I\'m running all my apps to make sure it\'s not just one app, and in every app I have, when I run on the iOS5 simulator or device, the viewWillAppear method get

4条回答
  •  抹茶落季
    2021-01-06 03:19

    Because you are displaying the view twice.

    First time by adding the view as a subview of the current view:

    [self.view addSubview:closeVC.view];
    

    Second time by pushing the view's controller on top of current view's controller:

    [self presentModalViewController:closeVC animated:NO];
    

    I'm not sure why in iOS4 the viewWillAppear was only called once, because iOS5 is correct to call it twice, given that you are displaying the view twice as explained above.

    Just remove one of the lines and it would be fine (I'd recommend removing the addSubview and retain the presentModalViewController one).

提交回复
热议问题