2016-06-17 3 views
-1

경고보기 컨트롤러를 표시하려고 할 때 응용 프로그램이 충돌합니다.PresentViewController가 목표 c에서 작동하지 않습니다. 응용 프로그램이 충돌합니다

-(void)setupAlertCtrl{ 
    self.alertCtrl=[UIAlertController alertControllerWithTitle:@"Select Image" 
                 message:nil 
               preferredStyle:UIAlertControllerStyleActionSheet]; 

} 
- (IBAction)selectImagePressed { 
    **[self presentViewController:self.alertCtrl 
         animated:YES 
        completion:nil];//this funcanility is breaking** 

} 

예외 :

의 libC++ abi.dylib : 형 NSException의 캐치되지 않는 예외로 종료

+1

충돌 로그를 공유하십시오. –

+0

'self'가 일부보기를 나타 냅니까? – mkumar

답변

0

당신이보기에서 아래 함수를 호출해야했던로드

-(void)setupAlertCtrl 

이 당신을 도울 것입니다

-(void)setupAlertCtrl 
{ 
    self.alertCtrl=[UIAlertController alertControllerWithTitle:@"Select Image" 
               message:nil 
             preferredStyle:UIAlertControllerStyleActionSheet]; 
    [self presentViewController:self.alertCtrl animated:YES completion:nil]; 
} 

-(IBAction)selectImagePressed 
{ 
    [self setupAlertCtrl]; 
} 

희망, 버튼의 경고가

0

당신은 같은를 작성해야한다 열기를 클릭합니다.

+0

도 작동하지 않습니다. –

+0

스토리 보드의 버튼을 사용하여 IBAction 연결에 대해 친절하게도 추락하지 않고 내 끝에서 잘 작동합니다. –

0

UIAlertControllerUIAlertViewUIActionSheet에 대해 기능적으로 동일한 블록 기반 대체품입니다. 경고 또는 작업 시트 간 전환은 컨트롤러를 만들 때 기본 스타일을 설정하여 수행됩니다. 나는이 당신을 도움이되기를 바랍니다

UIAlertController *alertController = [UIAlertController 
           alertControllerWithTitle:alertTitle 
           message:alertMessage 
           preferredStyle:UIAlertControllerStyleAlert]; 

[self presentViewController:alertController animated:YES completion:nil]; 

...

0

자사가 충돌하지, 그냥 viewDidLoad 방법에 SetupAlertCntrl 호출합니다. 작동합니다.

+0

나는 이미 –

+0

라고 불렀다 ... 당신은 alertController에 대한 약한 참조를 취했다. 그 속성을 강하고 논이 아닌 –

+0

으로 만들었고 –

0

alertController가 존재하는지 아닌지 먼저 확인해야합니다. 한 가지 더, UIAlertControl은 UIViewController에서만 표시 할 수 있으므로 selectImagePressed 함수의 self는 UIViewController와 같은 종류인지 확인하십시오.

- (IBAction)selectImagePressed { 
     if(self.alertController == nil) { 
     [self setupAlertCtrl]; 
     } 
     [self presentViewController:self.alertCtrl 
          animated:YES 
         completion:nil];//this funcanility is breaking** 

    } 
+0

더 많은 정보를 가지고 편집 해 주시기 바랍니다. 코드 전용 및 "시도하십시오"답변은 검색 가능한 콘텐츠가 없으므로 권장하지 않으며 누군가가 "시도해"야하는 이유를 설명하지 않습니다. 우리는 여기서 지식을위한 자원이되기 위해 노력합니다. – abarisone

+1

고정 된 @abarisone – Nick

0

의 libC++ abi.dylib : 형 NSException의 캐치되지 않는 예외로 종료 더 이상 존재하지 않는 IBAction를에 버튼을 유선 한 경우도 발생할 수

(또는 이름이 변경됨) "

스토리 보드로 이동하는 것보다이 문제가 발생하면 전화 개요 상단의 노란색 상자 아이콘 (컨트롤러보기)을 오른쪽 클릭하고 노란색으로 콘센트를 삭제하십시오 플래그.

이 경우 인스턴스에서 어떤 일이 일어 났는지 이름을 바꾼 것입니다.

희망이 도움이 될 것입니다. 코드 아래

0

시도 :

-(void)setupAlertCtrl 
{ 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Choose Profile Image " message:@" " preferredStyle:UIAlertControllerStyleActionSheet]; 

    UIAlertAction* cameraAction = [UIAlertAction actionWithTitle:@"Take Photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 
     NSLog(@"Camera Action"); 
    }]; 
    [alertController addAction:cameraAction]; 

    UIAlertAction* gallaryAction = [UIAlertAction actionWithTitle:@"Gallary" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 
     NSLog(@"Gallary Action"); 
    }]; 
    [alertController addAction:gallaryAction]; 

    UIAlertAction* Cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 
    [alertController addAction:Cancel]; 

    [self presentViewController:alertController animated:YES completion:nil]; 
} 

// 버튼을 클릭 행동이 당신을 도울 것입니다

- (IBAction)selectImagePressed:(id)sender 
    { 

    [self setupAlertCtrl]; 

    } 

희망.

1

이 코드는 분명 도움이 될 것입니다. 난 당신이 아이 패드 (아이 패드에서 정상 동작 시트 충돌)을 사용하는 의심 - (무효) setupAlertCtrl {

경우 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

{

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"Your message" preferredStyle:UIAlertControllerStyleActionSheet]; 

    // Remove arrow from action sheet. 
    [alertController.popoverPresentationController setPermittedArrowDirections:0]; 
    //For set action sheet to middle of view. 
    CGRect rect = self.view.frame; 
    rect.origin.x = self.view.frame.size.width/20; 
    rect.origin.y = self.view.frame.size.height/20; 
    alertController.popoverPresentationController.sourceView = self.view; 
    alertController.popoverPresentationController.sourceRect = rect; 

    [self presentViewController:alertController animated:YES completion:nil]; } 
else 
{ 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"Your message" preferredStyle:UIAlertControllerStyleActionSheet]; 
    [self presentViewController:alert animated:YES completion:nil]; 
} 

}

관련 문제