在应用程序rootviewController中分配了类似
navigationContr = [[UINavigationController alloc] initWithRootViewController:loginViewController];
loginViewController = nil;
self.window.rootViewController = _navigationViewController;
登录后我像这样推送MainViewController
MainViewController * mainViewController = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
mainViewController.isNavigateFromLogin = YES;
/** push the Main screen*/
[self.navigationController pushViewController:mainViewController animated:NO];
mainViewController = nil;
在MainViewController上我正在添加另一个viewController的视图,如下所示
gridViewControllerObj = [[GridViewController alloc]initWithNibName:@"GridViewController" bundle:nil];
[self.view addSubview:gridViewControllerObj.view];
GridViewController添加按钮,点击按钮我们显示popover。代码如下 内存分配给" operationsViewController"
self.optionsPopOver = [[UIPopoverController alloc]initWithContentViewController:operationsViewController];
[_orderOptionsPopOver presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:NO];
这是show popover的流程,如果在设备上运行app我在控制台上看到警告打印。超时后我回到第一个视图
问题1:
BusinessApplication [8321]:不鼓励在分离的视图控制器上呈现视图控制器。 对于这种情况,应用程序工作但不崩溃
要修复此警告,我在论坛上搜索了上述警告,有解决方案建议如
AppDelegate *appDelegate = (AppDelegate* )[[UIApplication sharedApplication] delegate];
UIView *rootView = appDelegate.window.rootViewController.view;
在上面的警告提示
之后提供rootview[_orderOptionsPopOver presentPopoverFromRect:frame inView:rootView permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:NO];
问题2: 应用上述解决方案后,应用程序崩溃。
我收到了崩溃日志
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
mstreamd[513] <Notice>: (Note ) PS: MSSubscriber - 1456278278 Finished retrieving assets. Checking for errors on 0 assets...
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
BusinessApplication[511] <Warning>: Stack Trace: uncaughtExceptionHandler
(
0 CoreFoundation 0x25f0fd7f <redacted> + 150
1 libobjc.A.dylib 0x33aefc77 objc_exception_throw + 38
2 UIKit 0x29696533 <redacted> + 2918
3 UIKit 0x2969809b <redacted> + 94
4 UIKit 0x293c11a1 <redacted> + 72
5 UIKit 0x29697fcf <redacted> + 198
6 UIKit 0x2949c199 <redacted> + 168
7 UIKit 0x294c5741 <redacted> + 116
8 UIKit 0x294c4721 <redacted> + 120
9 UIKit 0x294037a3 <redacted> + 66
10 Foundation 0x26c16dc9 __NSFireDelayedPerform + 468
11 CoreFoundation 0x25ed6517 <redacted> + 14
12 CoreFoundation 0x25ed6099 <redacted> + 656
13 CoreFoundation 0x25ed4303 <redacted> + 1418
14 CoreFoundation 0x25e21981 CFRunLoopRunSpecific + 476
15 CoreFoundation 0x25e21793 CFRunLoopRunInMode + 106
16 GraphicsServices 0x2d1b1051 GSEventRunModal + 136
17 UIKit 0x29413981 UIApplicationMain + 1440
18 BusinessApplication 0x003ddc17 main + 170
19 libdyld.dylib 0x3408baaf <redacted> + 2
)
BusinessApplication[511] <Warning>: CRASH: Application tried to present modally an active controller <MainViewController: 0x16a78b30>.
BusinessApplication[511] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <MainViewController: 0x16a78b30>.'
*** First throw call stack:
(0x25f0fd67 0x33aefc77 0x29696533 0x2969809b 0x293c11a1 0x29697fcf 0x2949c199 0x294c5741 0x294c4721 0x294037a3 0x26c16dc9 0x25ed6517 0x25ed6099 0x25ed4303 0x25e21981 0x25e21793 0x2d1b1051 0x29413981 0x3ddc17 0x3408baaf)
ReportCrash[516] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
ReportCrash[516] <Notice>: ReportCrash acting against PID 511
ReportCrash[516] <Notice>: Formulating crash report for process BusinessApplication[511]
mediaserverd[36] <Notice>: '' com.xp.businessApp(pid = 511) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
com.apple.xpc.launchd[1] (UIKitApplication:com.xp.businessApp[0x2b0f][511]) <Notice>: Service exited due to signal: Abort trap: 6
<Warning>: Application 'UIKitApplication:com.xp.businessApp[0x2b0f]' crashed.
assertiond[54] <Warning>: pid_suspend failed for <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511>: Unknown error: -1, Unknown error: -1
assertiond[54] <Warning>: Could not set priority of <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511> to 2, priority: No such process
assertiond[54] <Warning>: Could not set priority of <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511> to 4096, priority: No such process
UserEventAgent[17] <Warning>: id=com.xp.businessApp pid=511, state=0
ReportCrash[516] <Notice>: Saved report to /var/mobile/Library/Logs/CrashReporter/BusinessApplication_2015-03-14-171423_IPad.ips
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
mstreamd[513] <Notice>: (Note ) mstreamd: Not monitoring for external power.
mstreamd[513] <Notice>: (Note ) PS: Media stream daemon stopping.
mstreamd[513] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x14e30790>: Shared Streams daemon has shut down.
mstreamd[513] <Notice>: (Warn ) mstreamd: mstreamd shutting down.
<Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
<Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
答案 0 :(得分:0)
您所做的事情的问题在于您为自己创造了一个陷阱链。
您创建了几个控制器并显示它们,但在您呈现它们之后,您将释放它们。你不能提出你要解除分配的东西。这导致了第一个问题,当你的当前控制器为零时试图呈现另一个控制器。
接下来,您将收到错误消息并搜索脱离上下文的解决方案。这不是您的问题的解决方案,显然如果您尝试使用它会导致崩溃。
您需要做的第一件事是删除nil assign。我不知道你为什么要这样做,我确定它会造成很多问题。
当你有*a = *b
和*c = *a
时,如果你设置c = nil
,所有其他变量也将是零,因为它的指针是如何工作的。如果你不介意有人看你的代码,我很乐意为你提供更多的帮助,但如果有问题的电话仍在那里,我就无能为力。