Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 设置UITabBarControllers的selectedIndex属性后禁用自动旋转(SDK错误?)_Iphone_Ipad_Ios_Uitabbarcontroller_Autorotate - Fatal编程技术网

Iphone 设置UITabBarControllers的selectedIndex属性后禁用自动旋转(SDK错误?)

Iphone 设置UITabBarControllers的selectedIndex属性后禁用自动旋转(SDK错误?),iphone,ipad,ios,uitabbarcontroller,autorotate,Iphone,Ipad,Ios,Uitabbarcontroller,Autorotate,这个问题。我的申请中出现了一个非常奇怪的错误。我有一个UITabBarController,有几个选项卡的视图控制器。在视图控制器中,我通过shouldAutorotateToInterfaceOrientation:实现了自动旋转,在我进行以下更改之前,它工作正常 我在视图控制器中实现了滑动手势,以便在选项卡之间进行切换。这是通过以下代码实现的 - (void)onSwipeLeft { int _count = [[self.tabBarController.tabBar items]

这个问题。我的申请中出现了一个非常奇怪的错误。我有一个UITabBarController,有几个选项卡的视图控制器。在视图控制器中,我通过shouldAutorotateToInterfaceOrientation:实现了自动旋转,在我进行以下更改之前,它工作正常

我在视图控制器中实现了滑动手势,以便在选项卡之间进行切换。这是通过以下代码实现的

- (void)onSwipeLeft {
  int _count = [[self.tabBarController.tabBar items] count];
  int i = self.view.tag - 1;
  if (i < _count - 1) {
    self.tabBarController.selectedIndex = (i + 1) % _count;
  }
}
同样的道理,对吧

现在,只有向左或向右滑动时,自动旋转才起作用。在那之后,根本不会调用shouldAutorotateToInterfaceOrientation:

另见

在本文中,描述了相同的问题。我有时也看到 类似于以下内容的日志消息:-[UIWindow BegindAbgingInterfaceAutoRotation]上溢出。忽略。我找不到关于这个的任何其他信息

似乎在描述同样的问题

似乎正在描述类似的问题,但与popViewController:。请注意,该错误自SDK 3.2以来一直存在


怎么办?这似乎是SDK中的一个bug,它仍然存在于4.1中。有人找到解决办法了吗?这似乎是一种常见的情况。

我应该早点想到这一点

创建UIWindow并确保自动旋转。h:


UITabViewController是否符合自动旋转?因为它是其他视图的父视图,所以它也必须允许旋转。我尝试将UITabViewController子类化,并在shouldAutorotateToInterfaceOrientation:中返回YES,但这没有帮助。您能否解释为什么这是一个解决方案…一个空方法?这可能会导致次要影响,因为您正在覆盖扩展中的UIKit方法,而不考虑原始方法的功能。不建议这样做,更进一步,在扩展中这样做是非常模糊的,因为您实际上不知道将发生哪个实现。想象一下,如果您提供了多个覆盖同一方法的扩展。。。会发生什么?
#import <UIKit/UIKit.h>

@interface UIWindow (ensureAutorotation)

- (void)beginDisablingInterfaceAutorotation;
- (void)endDisablingInterfaceAutorotation;

@end
#import "UIWindow+ensureAutorotation.h"

@implementation UIWindow (ensureAutorotation)

- (void)beginDisablingInterfaceAutorotation {}
- (void)endDisablingInterfaceAutorotation{}

@end

// of course this can be added as a simple category, rather than .h .m files