当应用程序启动时,我将获得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 – 不在窗口层次结构中的模态视图控制器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)