dismissViewControllerAnimated causing the same view controller to load again

My scenario is the following:

  1. When the application load, the first controller is A
  2. The first time the application starts, it loads controller B which shows a video. A loads B using performSegueWithIdentifier in its viewDidAppear method. B
  3. B shows the video using MPMoviePlayerViewController. B recognizes that the video is finished using MPMoviePlayerPlaybackDidFinishNotification and than performs: [self dismissViewControllerAnimated:NO completion:nil];

The dismiss call causing B to reload (the movies plays again) and the following error appears in the console:

: CGImageCreate: invalid image size: 0 x 0.

How I can solve this issue?

Answers


The issue is with your logic to present ViewController B in the viewDidAppear: method of ViewController A.

When B is done and dismisses, the viewDidAppear: of A will be called (again) which in turn will present B again and the cycle will continue till something rots.

Basically:
  1. viewDidLoad of A
  2. viewDidAppear: of A
  3. B presents
  4. B dismisses
  5. viewDidAppear: of A
  6. B presents ...

You should re-think your logic because at this point, there are many ways to go about this.

Or... if this movie must play only once then you can present B in the viewDidLoad of A.


The call to dismissViewControllerAnimated will cause viewDidAppear to be invoked again on the first view controller A.

But you can distinguish between the first time the this view controller is begin presented using the method - (BOOL)[UIViewController isBeingPresented].

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];

  if ([self isBeingPresented]) {
    [self performSegueWithIdentifier:@"YourSegueIdentifier" sender:self];
  }
}

I would setup a property like didMoviePlay and check that in viewDidAppear: to decide whether the movie played or not. That way if there's an error with movie playback you can decide how to proceed from there.


Need Your Help

dynamic Jtree from database

java swing jdbc hashmap jtree

I have a database table named tree1, which has a table names student_details.This table has 3 columns student_name,student_details,student_phone

Spring RestTemplate readtimeout property not working properly - strange issue

java spring sockets weblogic resttemplate

I want to consume 2 services and want to have different timeouts. So, I have overridden Spring's SimpleClientHttpRequestFactory and using it from my HttpDaoImpl.