2009-09-03 12 views
5

UITabBarControllerは、横向きの向きを許可しません。だから、私はUITabBarContoller(RotatingTabBarControllerと呼ばれる)のサブクラスを使用しました。その唯一の目的は、shouldAutorotateToInterfaceOrientation呼び出しにYESを返すことでローテーションを許可することです。UITabBarControllerの横向きですか?

シミュレータでiPhoneを回転させると、次のようなmallocエラーが発生するという問題があります。

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

Snow Leopardで3.0 SDKとXcode 3.2を使用しています。私は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) 
+1

サブクラスの代わりにUITabBarControllerのカテゴリを使用して回転させることができました。これは私たちのために機能します。私はあなたのエラーについて何をすべきか分かりません。私はこの状況でそれにぶつからないので恐れています:( – Kevlar

+0

カテゴリの実装方法を説明してもらえますか? – Vic

+0

私はこのようなケブラーのアプローチを試みましたが、同じmalloc関数ポインタ解放エラーを取得:( // UITabBarController + Rotation.h @interface UITabBarController(回転) - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; @end // UITabBarController + Rotation.m #import "UITabBarController + Rotation.h" @implementation UITabBarController(rotation) - (BOOL)shouldAutorotateToInterf aceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } @end – Vic

答えて

8

これはiPhone SDK 3.0のバグです。 iPhone SDK 3.1で修正されました

0
というエラーが何かのように見える

は、どちらかのalloc/initをせずに解放されている、またはそれは、二重解放されています、あなたのサブクラス化でのエラーのように見えていませんまたはコード。

私はあなたの問題を解決するためにケブラーのカテゴリーアプローチが好きです。それは創造的でシンプルであり、あなたのために働くべきです。

+0

私はKevlarにカテゴリの実装方法を説明するように頼んだ。 – Vic

+0

カテゴリアプローチを試してもうまくいかない場合、それは問題があなたの子クラスではないという証拠です。それは別の場所です。あなたのalloc/init/releaseサイクルをチェックし、二重に解放していないことを確認してください – slf

+0

これは裸の骨プロジェクトです。 Xcodeでは、新しいテストプロジェクトを「タブバーアプリケーション」として作成しました。 2つのUIBarTabBarController + Rotation.h&.mファイルをプロジェクトに追加し、TestAppDelegate.hに#import "UITabBarController + Rotation.h"行を追加しました。それで、プロジェクトには他のコードはありませんが、まだこのエラーが出ています。 – Vic

8

サブタスクUITabBarControllerは、インターフェイスの回転を取得するための推奨方法ではありません。実際、アップルの文書では、UITabBarControllerまたはUINavigationControllerをサブクラス化しないように厳密に言及しています。 また、UITabBarControllerが自動回転をサポートするためには、UITabBarControllerによって管理されているすべてのコントローラがこの向き(この場合は横長)をサポートしている必要があるとも言われています。

+1

答えをありがとう。私はそれを読むまでサークルで走っていた。私の意見の一つはまだ完全ではなく、もちろん "はい"を返さなかった。 – R4cOON

+0

related:回転は私のために働いていました(すべての '管理された'コントローラがYESを返すというApple認定の方法を使用しています)、回転時にビューが自動的にサイズ変更されることはありませんでした。このナゲットは私を助けた:http://www.codebunnygames.com/?p=18 – mattorb

関連する問題