Chris Lin
Chris Lin

Reputation: 709

perform modal segue in a loop

I am working on merging same record into one by performing a looping if else statement and present modal view controller accordingly. basically if data is repeated, it will present a view and ask user if they want the merge data.

regardless what user picks, the app should dismiss the controller and check the next one, present again and so on

I am using storyboard with perform segue with id and prepare for segue, but it wont work...

does anyone have suggestion or hint how this could be done with storyboard?

Upvotes: 0

Views: 210

Answers (1)

vacawama
vacawama

Reputation: 154603

The problem with performing a modal segue in a loop is that the code does not block on the performSegue:withIdentifier call. Your main viewController loses control after the prepareForSeque call.

To get control back to your calling viewController, you should set up a delegate pointer in your destination view controller and set this delegate pointer to self in prepareForSegue. Also, define a modalViewControllerDidFinish method in your main viewController.

In your modal viewController, call [delegate modalViewControllerDidFinish] to return control to your main viewController.

Keep track of where you are in your processing by storing your state in properties in your main view controller. In your modalViewControllerDidFinish, call a method which will continue the work if there is more to be done.

Upvotes: 1

Related Questions