0

.xib로 모달 UIView를 만들고 버튼을 클릭하면이 UIView가 표시됩니다. 그러나 presentViewController 오류가 있습니다 : 'UIViewController'호환되지 않는 형식의 매개 변수에 'void'보내기. 귀하의 답변에 감사드립니다.'UIViewController'호환되지 않는 유형의 매개 변수에 'void'보내기

- (void)modal { 
    modalViewController *mvc = [[modalViewController alloc] initWithNibName:@"modalViewController" bundle:nil]; 
    UIView * modal = [[UIView alloc] initWithFrame:CGRectMake(self.view.center.x/2, self.view.center.y/2, 240, 320)]; 
    modal.backgroundColor = [UIColor whiteColor]; 
    [modal addSubview:mvc.view]; 
    [self.view addSubview:modal]; 
} 

- (IBAction)showBTN:(id)sender { 

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

} 

답변

4

presentViewController:animated:completion: 첫번째 파라미터 UIViewController하지 void의 인스턴스이다.

modalViewController의보기를 이미 UIViewControllers보기로 추가하고 있으므로 수행하려는 작업이 의미가 없습니다. 따라서 presentViewController:animated:completion:으로 전화 할 필요가 없습니다.

이 현재 뷰 계층에보기를 추가합니다 : 또한


- (IBAction)showBTN:(id)sender { 
    [self modal]; 
} 
작은 말, 수업은 그래서 당신의 modalViewController 클래스는 실제로 ModalViewController을 이름을 지정해야합니다, 대문자로 시작해야합니다.