안녕하세요
Xcode Object-C 로 구성된 소스에서
아이폰과 아이패드에서 UIAlertController 구현하는 중
각각 다르게 주어지지 안으면 Crash가 발생되는 경우
각각의 향(Device)의 구분을 지어 주어야 한다
특히 아이패드 에서
popoverPresentationController 항목을 넣어서 ActionSheet 로 사용 하지 않으면 100% Crush 가 발생 한다
또한 sourceRect (ActionSheet의 위치), sourceView (ActionSheet를 띄울 View) ,permittedArrowDirections(ActionSheet의 화살표 방향 설정 ) 등등의 옵션을 같이 해주어야 한다.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
// 아이폰
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Select Language" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
for (NSDictionary *dic in theDataManager.languageList)
{
NSString *lang = [dic objectForKey:@"title"];
UIAlertAction *defaultAct = [UIAlertAction actionWithTitle:lang style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *language = [dic objectForKey:@"code"];
theDataManager.currentLanguage = language;
[theMenu loadMenu];
[self logoChangeConstraint:theDataManager.currentLanguage];
if (![[theDelegate.navigationController.viewControllers objectAtIndex:0] isKindOfClass:[MainViewController class]]){
theDelegate.navigationController.viewControllers = @[[[MainViewController alloc] init]];
[theDelegate.navigationController popToRootViewControllerAnimated:NO];
}
[thePlayerView loadPlayerPopupList];
}];
[alert addAction:defaultAct];
}
UINavigationController *navi = [(AppDelegate *)[[UIApplication sharedApplication] delegate] navigationController];
[navi presentViewController:alert animated:YES completion:nil];
}else{
// 그외 아이패드
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Select Language" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
for (NSDictionary *dic in theDataManager.languageList)
{
NSString *lang = [dic objectForKey:@"title"];
UIAlertAction *defaultAct = [UIAlertAction actionWithTitle:lang style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *language = [dic objectForKey:@"code"];
theDataManager.currentLanguage = language;
[theMenu loadMenu];
NSLog(@"languages %@", language);
//언어변경에 따른 로고이미지 변경 2022.01.07 ktw
[self logoChangeConstraint:theDataManager.currentLanguage];
if (![[theDelegate.navigationController.viewControllers objectAtIndex:0] isKindOfClass:[MainViewController class]]){
theDelegate.navigationController.viewControllers = @[[[MainViewController alloc] init]];
[theDelegate.navigationController popToRootViewControllerAnimated:NO];
}
[thePlayerView loadPlayerPopupList];
}];
[alert addAction:defaultAct];
}
UINavigationController *navi = [(AppDelegate *)[[UIApplication sharedApplication] delegate] navigationController];
// show action sheet
alert.popoverPresentationController.permittedArrowDirections = 0;
CGRect rect = navi.view.frame;
rect.origin.x = 0;
//rect.origin.y = 0;
rect.origin.y = navi.view.frame.size.height / 10;
alert.popoverPresentationController.sourceRect = rect;
alert.popoverPresentationController.sourceView = navi.view;
[navi presentViewController:alert animated:YES completion:nil];
}
'iOS, Swift 개발' 카테고리의 다른 글
구글 AdMob 과 Ad Manager 차이점, 개발 그리고 수익 결과 (0) | 2024.03.25 |
---|---|
iOS 애플 디벨로퍼 프로그램 맴버쉽(Apple Developer Program Membership) 갱신 (0) | 2024.03.19 |
AvPlayer 재생 시간과 소수점 변환 구하기 (0) | 2024.03.15 |
iOS App Store 유럽 연합(EU) 디지털 서비스법(DSA) 규정 준수 (1) | 2024.03.15 |
Google Play 정책 회원 탈퇴 요청 (0) | 2023.11.14 |