如何获得当前活动视图控制器?

时间:2022-06-13 07:32:20

I'm having this issue (error is reported by Flurry analytics from some users, but I cannot reproduce it neither on my device nor simulator):

我有这个问题(有些用户会报告Flurry analytics的错误,但我不能在我的设备或模拟器上重现):

NSInvalidArgumentException: Application tried to present modally an active controller <CityViewController: 0x361b20>.

NSInvalidArgumentException:应用程序试图以模式显示一个活动控制器

Do you know anything about this error? Has it happened to you?

你知道这个错误吗?发生在你身上了吗?

Application has three hierachically sorted views: master view controller with list of locations and detail view (the CityViewController mentioned in error message) is automatically presented when user is at one of known locations. Whenever location significantly changes, detail view is dismissed first before opening new location to prevent this. However, it apparently doesn't help.

应用程序有三个按层次结构排序的视图:主视图控制器,包含位置列表和细节视图(错误消息中提到的CityViewController),当用户位于一个已知位置时自动显示。每当位置发生重大变化时,在打开新位置之前,要先排除细节视图。然而,这显然没有帮助。

CityViewController can also open SMS composer as its child.

CityViewController也可以作为它的子元素打开SMS composer。

3 个解决方案

#1


15  

To get the currently visible view you can use:

要获得当前可见的视图,您可以使用:

[self.navigationController visibleViewController];

#2


3  

So the reply to original question: How do i get current active view controller?

那么对原始问题的回答是:如何获得当前活动视图控制器?

The answer lies in [self.navigationController presentedViewController] instead of topViewController or anything else.

答案在于[自我]。navigationcontrollerpresentedviewcontroller]而不是topViewController或其他东西。

#3


0  

If you are launching the modal view when some event is fired, seems probable that you are trying to show that view again while it is already active...

如果您在触发某个事件时启动模式视图,那么很可能您正在尝试在该视图已处于活动状态时再次显示该视图……

#1


15  

To get the currently visible view you can use:

要获得当前可见的视图,您可以使用:

[self.navigationController visibleViewController];

#2


3  

So the reply to original question: How do i get current active view controller?

那么对原始问题的回答是:如何获得当前活动视图控制器?

The answer lies in [self.navigationController presentedViewController] instead of topViewController or anything else.

答案在于[自我]。navigationcontrollerpresentedviewcontroller]而不是topViewController或其他东西。

#3


0  

If you are launching the modal view when some event is fired, seems probable that you are trying to show that view again while it is already active...

如果您在触发某个事件时启动模式视图,那么很可能您正在尝试在该视图已处于活动状态时再次显示该视图……