最近、アプリでマルチタスクを有効にしました(バックグラウンド時に終了せず)ユーザーが予期せぬ時間にクラッシュするようになりました。クラッシュログは、viewDidLoadでクラッシュが発生したことを示します。バックグラウンドから戻るときにviewDidLoadがクラッシュする
私のviewDidLoadアプローチはおそらく、とにかく考え直す必要があります。私はxibからロードされたビューのいくつかを持っているので、残りの階層をプログラムでビルドします(いくつかの自動リリースされたUIButtonを含みますが、クラッシュすると思います)。どんなことが起こっているのか、これにもっと近づく方法についての洞察はありますか?
はここで、一般的なクラッシュレポートです:最も参考になる何
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x49ef527e
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x32da1c9a objc_msgSend + 18
1 App 0x0000a890 -[EntryViewController viewDidLoad] (EntryViewController.m:270)
2 UIKit 0x3241ff08 -[UIViewController view] + 104
3 UIKit 0x3242c1ce -[UIViewController viewControllerForRotation] + 34
4 UIKit 0x3242ca40 -[UIViewController shouldWindowUseOnePartInterfaceRotationAnimation:] + 8
5 UIKit 0x3242c9a8 -[UIWindow _clientsForRotation] + 236
6 UIKit 0x32494fea -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 70
7 UIKit 0x32493f9e -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 946
8 UIKit 0x324bec50 -[UIViewController _dismissModalViewControllerWithTransition:from:] + 1444
9 UIKit 0x324be5e0 -[UIViewController dismissModalViewControllerWithTransition:] + 596
10 UIKit 0x324be366 -[UIViewController dismissModalViewControllerAnimated:] + 86
ロード/アンロードサイクル全体でビュー階層を管理するためのベスト・プラクティスに簡単に説明します。私はIBOutletがviewDidUnloadのnilに設定された保持されたプロパティであるべきであることを知っています。
しかし、プログラムで作成されたUIViewとUIControlはどうですか? ViewDidLoadでローカルオブジェクトを作成し、それをビューに追加してリリースしたら、もう一度気にする必要はありませんか?私がdeallocまで解放しない、ivarsでalloc-init'edビューを使用するといいですか? [OK]を私は決してリリースするオートリリースビューを使用するには?
はここに私のviewDidLoadの一部です:
imagebg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.view addSubview:imagebg];
[self positionBackgroundAt:0];
UIButton *flickbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[flickbtn addTarget:self action:@selector(flick:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:flickbtn];
[flickbtn release];
// SET UP UPPER LEFT BUTTONS
upperLeftButton0 = [UIButton buttonWithType:UIButtonTypeCustom];
[upperLeftButton0 setFrame:CGRectZero];
[self.view addSubview:upperLeftButton0];
upperLeftButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[upperLeftButton1 setFrame:CGRectZero];
[self.view addSubview:upperLeftButton1];
// SET UP DISPLAY
displayimg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"newdisplay.png"]];
[displayimg setCenter:CGPointMake(CGRectGetMidX(self.view.frame),CGRectGetMaxY(self.view.frame) - 57)];
[self.view addSubview:displayimg];
[displayimg release];
...
私viewDidUnloadはちょうどnilにすべてIBOutletsを設定します。
ありがとうございました。
あなたはいくつかのコードとあなたが取得しているエラー・スタックを投稿する必要があります。 – csano
j0kが言ったように、問題の内容を絞り込むためのコードを表示する必要があります – REALFREE
リリース後に 'nil'に設定されていなかった' viewDidUnload'でリリースされたオブジェクトにアクセスすると仮定します。 –