UITabBarController的横向方向?

时间:2009-09-03 18:27:18

标签: iphone uitabbarcontroller landscape

UITabBarController不允许横向显示。所以我使用了UITabBarContoller的子类(称为RotatingTabBarController)。它的唯一目的是通过将YES返回到shouldAutorotateToInterfaceOrientation调用来允许旋转。

问题是当你在模拟器中旋转iPhone时,会出现以下malloc错误。

malloc: *** error for object 0x3888000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

我在Snow Leopard上使用带有Xcode 3.2的3.0 SDK。我在malloc_error_break中设置了一个断点,但是我无法将其追溯到我的代码中。 我能做些什么来消除这个错误吗?

这是RotatingTabBarController类:

#import <UIKit/UIKit.h>
@interface RotatingTabBarController : UITabBarController {
}
@end 

@implementation RotatingTabBarController
-(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end

更新

我尝试了一个类别。但它给出了相同的malloc错误。

// UITabBarController+Rotation.h
@interface UITabBarController (rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end

// UITabBarController+Rotation.m
#import "UITabBarController+Rotation.h"

@implementation UITabBarController (rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   return YES;
}
@end

回溯

[Session started at 2009-09-05 12:13:19 -0400.]
Untitled(992,0xa06d9500) malloc: *** error for object 0x2024000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Untitled(992,0xa06d9500) malloc: *** error for object 0x2014000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

[Session started at 2009-09-05 12:13:27 -0400.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Fri Jul  3 01:19:56 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".Attaching to process 992.
sharedlibrary apply-load-rules all
(gdb) bt
#0  0x951908fa in mach_msg_trap ()
#1  0x95191067 in mach_msg ()
#2  0x30244d62 in CFRunLoopRunSpecific ()
#3  0x30244628 in CFRunLoopRunInMode ()
#4  0x32044c31 in GSEventRunModal ()
#5  0x32044cf6 in GSEventRun ()
#6  0x309021ee in UIApplicationMain ()
#7  0x00002608 in main (argc=1, argv=0xbfffef94) at /Users/vishwas/Desktop/Untitled/main.m:13
(gdb) 

3 个答案:

答案 0 :(得分:8)

这是iPhone SDK 3.0中的一个错误。它已在iPhone SDK 3.1中修复

答案 1 :(得分:8)

不推荐使用UITabBarController子类化来获取接口旋转。事实上,Apple的文档严格地说不要继承UITabBarController或UINavigationController。 它还说,为了让UITabBarController支持自动旋转,所有由它管理的控制器必须支持这种方向(即在这种情况下为横向)。

答案 2 :(得分:0)

该错误看起来像是在没有alloc / init的情况下被释放,或者它被双重释放,在您的子类或代码中看起来不像是错误。

我喜欢Kevlar的类别方法来解决您的问题,它具有创造性,简单,并且适合您。