大佬教程收集整理的这篇文章主要介绍了ios – 不在窗口层次结构中的模态视图控制器,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当应用程序启动时,我将获得AppDelegate中的用户位置,当我获得准确性时,我需要AppDelegate将Nsnotification发送到我的应用程序的起始页面(标签栏控制器的索引0).
收到通知后,此视图会尝试发送包含用户坐标和其他数据的电子邮件,但只要出现MFMailComposeViewController,我就会收到以下错误:
Warning: Attempt to present <MFMailComposeViewController: 0x98a0270> on <UITabBarController: 0x988c630> whose view is not in the window hierarchy!
我错过了什么?
谢谢.
这是我在AppDelegate.m中得到的:
- (void) LOCATIOnManager:(CLLOCATIOnManager *)manager didupdateToLOCATIOn:(CLLOCATIOn *)newLOCATIOn fromLOCATIOn:(CLLOCATIOn *)oldLOCATIOn { NSUserDefaults *phonenumbers = [NSUserDefaults standardUserDefaults]; NSDate *eventDate = newLOCATIOn.timestamp; NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; if (abs(howRecent) < 10.0) { [self LOCATIOnupdate:newLOCATIOn]; smsLoc = newLOCATIOn; if ([[phonenumbers objectForKey:@"sendSMS"] isEqualToString:@"yes"]) { [[NsnotificationCenter defaultCenter] postNotificationName:@"sendSMS" object:nil]; } else if ([[phonenumbers objectForKey:@"sendEmail"] isEqualToString:@"yes"]) { [[NsnotificationCenter defaultCenter] postNotificationName:@"sendEmail" object:nil]; } } }
- (void)viewDidLoad { [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(sendSMS:) name:@"sendSMS" object:nil]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(sendEmail:) name:@"sendEmail" object:nil]; }
最后,“sendSMS”的选择器(另一个非常相似):
- (void)sendSMS: (Nsnotification *)notification { NSUserDefaults *phonenumbers = [NSUserDefaults standardUserDefaults]; if ([phonenumbers objectForKey:@"first"] || [phonenumbers objectForKey:@"second"]) { MFmessageComposeViewController *controller = [[MFmessageComposeViewController alloc] init]; if ([MFmessageComposeViewController canSendText]) { AppDelegate *deleg = (AppDelegate *)[[UIApplication sharedApplication] delegate]; controller.body = [NSString StringWithFormat:@"some message with coordinates %.4f - %.4f",[deleg currentLOCATIOn].coordinate.latitude,[deleg currentLOCATIOn].coordinate.longitude]; controller.recipients = [NSArray arrayWithObjects:[phonenumbers objectForKey:@"first"],[phonenumbers objectForKey:@"second"],nil]; controller.messageComposeDelegate = self; [self presentModalViewController:controller animated:YES]; } } } }
UITabBarController *tabBarController = [[UITabBarController alloc] init]; tabBarController.delegate = self; tabBarController.SELEctedIndex = 0; [[tabBarController.tabBar.items objectATindex:0] settitle:NSLocalizedString(@"Home",nil)]; [[tabBarController.tabBar.items objectATindex:1] settitle:NSLocalizedString(@"requests",nil)]; [[tabBarController.tabBar.items objectATindex:2] settitle:NSLocalizedString(@"Account",nil)]; [[tabBarController.tabBar.items objectATindex:3] settitle:NSLocalizedString(@"SetTings",nil)]; //some other controls from DB [[tabBarController.tabBar.items objectATindex:1] setBadgeValue:[NSString StringWithFormat:@"%d",number]];
tabbarController是通过IB制作的,但我在AppDelegate中添加了上面的代码,因为我需要本地化标签栏项目并为其中一个添加徽章.
我在这里做错了吗?
[VC1 presentModalViewController:VC2]; // Error here,since VC1 is no longer visible on the window [VC1 presentModalViewController:VC3];
如果您的问题如上所述,您可以修复它:
if (self.modalViewController != nil) { [self.modalViewController presentModalViewController:VC3 animated:YES]; } else { [self.tabBarController presentModalViewController:VC3 animated:YES]; }
如果这不能解决您的问题,也许您可以尝试使用self.tabBarController而不是self来呈现.再一次只是建议,不知道它是否有效.
以上是大佬教程为你收集整理的ios – 不在窗口层次结构中的模态视图控制器全部内容,希望文章能够帮你解决ios – 不在窗口层次结构中的模态视图控制器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。