최근에 앱을 사용하여 멀티 태스킹을 활성화했으며 (백그라운드에서 종료하지 않음) 사용자가 예기치 않은 시간에 충돌을 일으켰습니다. 충돌 로그는 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에서 로컬 객체를 만들고 뷰에 추가 한 다음 해제하면 다시 걱정하지 않아도됩니까? Okalloc가 해제 될 때까지 ivars에서 alloc-init'ed 뷰를 사용하는 것이 좋습니다. 자동 배포 된보기를 사용하면 좋습니다.
은 여기 내있는 viewDidLoad의 일부입니다 :
내 viewDidUnload 그냥 전무 모든 IBOutlets를 설정
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];
....
감사합니다.
일부 코드와 오류 스택을 게시해야합니다. – csano
j0k가 말했듯이 문제의 범위를 좁히기 위해 몇 가지 코드를 보여 주어야합니다. – REALFREE
release 다음에'nil'으로 설정되지 않은'viewDidUnload'에서 해제 된 객체에 액세스한다고 가정합니다. –