Я работаю над универсальным приложением для форм-факторов iPhone 6S/6S Plus и iPad. Обычно представление таблиц действий/alertviews в приложении для 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