Question

Le UITabBarController ne permet pas l'orientation paysage. Donc, j'ai utilisé une sous-classe de UITabBarContoller (appelé RotatingTabBarController). Son seul but pour permettre une rotation en retournant OUI à l'appel de shouldAutorotateToInterfaceOrientation.

Le problème est que lorsque vous faites pivoter l'iPhone dans le simulateur, il donne l'erreur malloc suivant.

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

J'utilise 3.0 SDK avec Xcode 3.2 sur Snow Leopard. Je mis un point d'arrêt dans malloc_error_break mais je ne peux pas remonter à mon code. Y at-il quelque chose que je peux faire pour cette erreur aller?

Voici la classe RotatingTabBarController:

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

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

Mise à jour:

J'ai essayé la même chose avec une catégorie. Mais il donne la même erreur 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

Backtrace

[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) 
Était-ce utile?

La solution

Ceci est un bogue dans iPhone SDK 3.0. Il est fixé dans l'iPhone SDK 3.1

Autres conseils

Subclassing UITabBarController est pas une méthode recommandée pour obtenir la rotation de l'interface. En fait, la documentation d'Apple dit strictement ne pas sous-classe soit UITabBarController ou UINavigationController. Il dit aussi que pour UITabBarController pour soutenir autorotation, tous les contrôleurs « gérés » par elle doit prendre en charge cette orientation (paysage i.e. dans ce cas).

Cette erreur ressemble à quelque chose est soit d'être libéré sans alloc / init, ou il est en cours à double libéré, ne ressemble pas à une erreur dans votre sous-classage ou un code.

J'aime l'approche de la catégorie de Kevlar pour résoudre votre problème, il est créatif, simple, et devrait travailler pour vous.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top