私は、iPhone 6S/6S Plus/iPadフォームファクタ用の汎用アプリを開発中です。通常、iPhone専用アプリでアクションシート/アラートビューを提示するのは簡単な方法です。しかし、私のアプリケーションがクラッシュした私は、次のエラーを返す、iPad上でこれらを提示しようとすると:ユニバーサルアプリケーションのUIAlertControllerとUIPopoverController?
"Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController() of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'"
これは、アプリケーションがiPadの代わりに、従来のactionsheet上で動作しているとき、私はポップオーバーを表示しなければならない私の理解です。コンテキストのために、アクションシートは、テーブルビュー内にあるカスタムセルのボタンによって表示されます。
ユニバーサルアプリケーションでUIAlertControllers/Action Sheets/UIPopoverControllersを処理する最良の方法は何ですか?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *titleToUse = @"";
// switch (self.openGroup) {
// case 0:
// titleToUse = [self.deviceListData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// case 1:
// titleToUse = [self.computersData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// case 2:
// titleToUse = [self.mobileData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// case 3:
// titleToUse = [self.smartData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// default:
// break;
// }
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:titleToUse message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// Cancel button tappped.
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Get More Info" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
AlertDetailModal *alertDetail = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"alertDetailModal"];
alertDetail.delegate = self;
alertDetail.securityLevel = self.securityLevel;
UINavigationController *modalNavCon = [[UINavigationController alloc] initWithRootViewController:alertDetail];
[self presentViewController:modalNavCon animated:YES completion:nil];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Bandwidth Profile" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Alert Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Security Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Unblock Connection" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
}
パーフェクト!ありがとう、非常に簡潔かつ明確な答え:) – arcade16