사용자가 '추가'버튼을 누르면 모달 뷰가 팝업되어 정보를 입력합니다. 탐색 막대의 왼쪽 상단에 '취소'버튼이 있으며 눌렀을 때 현재보기 컨트롤러를 닫으려고합니다. 개체를 클래스의 대리자로 설정하려면 어떻게해야합니까? 나는 프로토콜을 만들고 그 메소드를 구현하는 것을 이해하지만, 위임자를 설정할 수는 없다. 디버거를 실행할 때 '추가'보기 컨트롤러에서 내 [self delegate]
은 항상 nil
입니다.Xcode의 위임
1
A
답변
0
당신은 당신의 스토리 보드에서 설정 SEGUE을 통해 모달의 ViewController을 산란하고 있습니까? 그렇다면 prepareForSegue:
메서드에서 대리자를 설정합니다. 당신이 코드를 통해 완전히 모달의 ViewController를 설정하는 경우, 다른 한편으로
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([identifier isEqualToString:@"userGuideSegue_home"]){
UserGuideViewController* vc = segue.destinationViewController;
[[segue destinationViewController] setDelegate:self];
}
}
는, 당신은 다음 모달의 ViewController의 인스턴스를 만들고 그것의 대리자를 설정합니다. 이 모든 당신을지지 물론
- (void)showModelView:(NSString*)viewName
{
// code ripped out of project so a bit specific
if ([viewName isEqualToString:@"userGuide_name"]) {
modalViewController = (UserGuideViewController *)
[[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:NULL]
instantiateViewControllerWithIdentifier:@"UserGuide"];
}
modalViewController.delegate = self;
modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
modalViewController.view.frame = [[UIScreen mainScreen] applicationFrame];;
[self presentViewController:modalViewController
animated:YES
completion:^{
//put your code here
}];
}
은 모달의 ViewController에 delegate
속성을 정의했습니다.
0
IB에서보기를 만든 경우, 단추를 ViewController의 헤더 파일로 Control- 드래그하고 IBOutlet을 추가하십시오. 하는 .m 파일에 메소드의 내부는
[self dismissModalViewControllerAnimated:YES];
는 다른 방법으로 프로그래밍 방식으로 버튼을 생성 할 수 있습니다
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(processCancel:)];
-(void)processCancel:(UIBarButtonItem *)item{
[self dismissModalViewControllerAnimated:YES];
}
0
@interface MyViewController : UIViewController {
id delegate;
}
@property (nonatomic,retain) id delegate;
@synthesize delegate;
이 작업을 수행해야합니다, 당신은 지금 모달 뷰를 표시하기 전에 [MyViewController setDelegate:self]
를 사용하고 MyViewController
관련 문제
- 1. 위임 위임
- 2. Kerberos 클라이언트 위임 위임 방화벽
- 3. 더 좋은 방법이 있습니까? 위임 -> 위임 -> 위임
- 4. 콜백/위임
- 5. NSComboBox 위임
- 6. 위임 작동하지
- 7. ASIHTTPRequest 위임
- 8. 위임 오류가
- 9. 위임 이벤트
- 10. 아이폰 위임
- 11. UIPopoverController 위임
- 12. 위임 'grandchild'보기에서
- 13. 람다 위임
- 14. Xcode의 다른보기에서보기보기
- 15. Xcode의 폴더
- 16. Xcode의 키로거?
- 17. Xcode의 프로젝트
- 18. Xcode의 디버깅
- 19. Xcode의 fortran
- 20. xcode의 자막
- 21. 별도의 위임 클래스
- 22. jQuery : 자체 위임?
- 23. 적인 Cocos2D 위임 질문
- 24. 목표 - C 위임 질문
- 25. 클래스의 이벤트 위임 문제
- 26. 함수를 위임 대상으로 변환
- 27. 구현 위임 콜백 방법
- 28. NSNetService 위임 및 ARC
- 29. 위임 모든 방법은 협회
- 30. 대상에 대한 이벤트 위임
감사의 버튼 취소 탭 이벤트에
[[self delegate] dismissModalViewControllerAnimated:YES]
를 호출 할 수 있습니다! 당신의 설명이 정말 도움이되었습니다. –