현재 두 개의 옵션 버튼이있는 UIAlertView가 있습니다. 사용자가 버튼 중 하나를 누르면, 나는 같은 객체에있는 메서드를 호출하여 웹에서 파일을 가져오고 싶습니다.UIAlertView clickButtonAtIndex EXC_BAD_ACCESS
나는 메서드를 잘 호출 할 수 있으며 NSLog()를 호출 할 수 있지만 모든 객체 변수를 사용하자마자 EXC_BAD_ACCESS 오류가 발생합니다.
내 첫 번째 생각은 스레딩 문제 일 수 있으므로 NSNotificationCenter를 호출하면 문제가 해결 될 수 있지만 같은 오류가 발생합니다.
아래 코드는 제가 지금 가지고있는 코드입니다. 몇 가지 다른 것들을 시도해 보았습니다 (일부는 주석으로 처리되었습니다). 'dbURL'개체는 클래스의 속성입니다. (편집 : 코드 아래에 완료되지 않음) 사전에
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//If database update
[[NSNotificationCenter defaultCenter] postNotificationName:@"newdb" object:self]; //EXC_BAD_ACCESS happens here
if ([alertView.title isEqualToString: @"Database Update"]){
switch (buttonIndex) {
case 0:
//[self getNewDatabase];
//[self performSelectorOnMainThread:@selector(getNewDatabase) withObject:nil waitUntilDone:NO];
//[NSThread detachNewThreadSelector:@selector(getNewDatabase) toTarget:self withObject:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"newdb" object:self];
break;
// Get a new database file from the server
- (void)getNewDatabase{
NSLog(@"in database: %@", dbURL);
}
감사합니다!
동일한 클래스에서 둘 이상의 UIAlertView 인스턴스를 사용합니까? –
예, 그렇지만 서로 간섭하지 않습니다. – Mabbage
궁금한데 왜'(alertView.title == @ "Database Update")를 사용하고 계십니까? Matteo Alessani가 게시 했으므로이 비교는 예상대로 작동하지 않습니다. NSZombieEnabled를 활성화하고 콘솔에서 오류를 덤프 할 수 있습니까? stacktrace도 도움이 될 것입니다. –