Question

I have created a new project to experiment MultipeerConnectivity. I added these lines to present a viewcontroller in viewDidLoad, but it not comes up. Why? Only a white background I can see.

MCBrowserViewController *browserViewController =
[[MCBrowserViewController alloc] initWithBrowser:browser
                                         session:session];
browserViewController.delegate = self;

self.modalPresentationStyle = UIModalPresentationFullScreen;

[self presentViewController:browserViewController animated:YES completion:
 ^{
     [browser startBrowsingForPeers];
 }];

UPDATE:

I see this in the console:

Warning: Attempt to present MCBrowserViewController: whose view is not in the window hierarchy!

Was it helpful?

Solution

The issue is that you're calling this in viewDidLoad. At that point the view is created but it's not visible anywhere, which means that the view controller has not yet appeared. You need to perform this method on viewDidAppear:.

OTHER TIPS

I think you missed something in the view controllers' initialization. Do you properly instantiate a view hierarchy for the view controller? What does it mean "but it not comes up". Can you only see a white background of the presenting view controller or of the presented view Controller? Try to set a breakpoint in the completion block. Is browser defined? Does the completion callback even get called?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top