Managing view hierarchy when opening a document

141 views Asked by At

I have an IOS App that can open a specific type of documents.

My App receives the document through:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

when it was not yet started or through

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 

when the App was already started.

When my App is already started the user may have already opened many views in my App. Next when my App is triggered to open the document, how can I open and navigate to the right view (closing the old hierarchy and open the new one to display the document)?

I have tried to use:

- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

with fromViewController = the rootViewController (retrieved using UIApplication & UIWindow) and the toViewController: the ViewController I need to display the document but without success.

Any ideas how to progress on this topic? Thanks,

Sébastien.

1

There are 1 answers

2
Omar Abdelhafith On BEST ANSWER

There isnt a quick answer to this question I faced your same problem, where i had a ReaderViewController that reads the documents I had a MainViewController that pushed the ReaderViewController as a modal controller

In my situation when the user opened an external document, i would do the following • pop the existing view controller • read the url, copy the file • open the document • present a new ReaderViewController with the new document

And that did it for me, But i dont think there will be an exact solution to be implemented in each case of openURL I think you should work on your view hierarchy more and study your own situation to see what views you should pop or dismiss and what views you should push or present