【发布时间】:2014-03-04 08:33:58
【问题描述】:
我的 UIViewController 中有一些非常奇怪的行为。我正在通过 Multipeer Framework 连接两台设备,一旦 iPhone 开始发送数据,我希望另一台 iPhone 显示一个 UIViewController 来处理接收到的数据。所以一旦 iPhone A 开始发送,iPhone B 就会发布一个 NSNotification。通知很快到达,下面的代码正在执行:
- (void)presentPeerView:(NSNotification *)notif
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ClientViewController *clientView = (ClientViewController *)[storyboard instantiateViewControllerWithIdentifier:@"peerView"];
[clientView setImage:_image];
clientView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.window.rootViewController presentViewController:clientView animated:YES completion:nil];
}
现在奇怪的部分来了。首先,显示 ClientViewController。但是没有动画,它只是凭空出现。我的 viewDidLoad 被调用并运行以下代码:
- (void)viewDidLoad
{
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[self blurImage:_image];
[self.imageView setImage:_image];
}
现在,我看到了模糊的图像,这很好。但是(非模糊)图像不会显示在 UIImageView 中。我的意思是图像得到了正确传递,否则我看不到模糊的背景。 我还有一些来自故事板的界面元素:
所以 UIViewController 加载了模糊的背景图像:
如您所见,没有加载任何 Storyboard UI 元素,除了 UISwitch(看起来也很奇怪)。 几秒钟后(取决于,有时最多 30 秒,有时只有 3 秒)整个 UI 加载:
所以,也许你们中的某些人以前也遇到过同样的问题,我真的不明白为什么 UI 确实需要这么多时间来“加载”。 CPU 百分比在 3% 左右。
我还在这个完成块中添加了一个 NSLog():
[self.window.rootViewController presentViewController:clientView animated:YES completion:^{
NSLog(@"done.");
}];
即刻调用。 viewDidLoad 似乎工作正常,没有任何线条可能会卡住,如果我在 viewDidLoad 结束时执行 NSLog,它也会立即被调用,但是视图(如下图所示)没有加载(完全)。
【问题讨论】:
标签: ios objective-c uiviewcontroller