0

我创建了一个新项目来试验 MultipeerConnectivity。我添加了这些行以在 viewDidLoad 中显示一个视图控制器,但它没有出现。为什么?我只能看到白色背景。

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

self.modalPresentationStyle = UIModalPresentationFullScreen;

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

更新:

我在控制台中看到了这个:

警告:尝试呈现 MCBrowserViewController:其视图不在窗口层次结构中!

4

2 回答 2

3

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:.

于 2014-05-09T10:39:05.027 回答
0

我认为您在视图控制器的初始化中遗漏了一些东西。您是否正确地为视图控制器实例化视图层次结构?“但它没有出现”是什么意思。您只能看到呈现视图控制器或呈现视图控制器的白色背景吗?尝试在完成块中设置断点。浏览器是否定义?完成回调是否会被调用?

于 2014-05-09T10:33:19.420 回答