arc*_*e16 6 objective-c uiactionsheet uipopovercontroller ios uialertcontroller
我正在开发适用于iPhone 6S/6S Plus /和iPad外形的通用应用程序.通常,在仅限iPhone的应用程序上呈现动作表/警报视图是一种简单的方式.但是当我尝试在iPad上显示这些应用程序时,我的应用程序崩溃,返回以下错误:
"终止应用程序由于未捕获的异常'NSGenericException’,原因是:"你的应用程序的风格UIAlertControllerStyleActionSheet的提出了UIAlertController()一UIAlertController的这种风格的modalPresentationStyle是UIModalPresentationPopover你必须通过报警控制器的popoverPresentationController提供位置信息,该酥料饼.您必须提供sourceView和sourceRect或barButtonItem.如果在显示警报控制器时不知道此信息,您可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供它.
据我所知,当应用程序在iPad上运行而不是传统的操作表时,我必须显示一个弹出窗口.为了上下文,操作表由自定义单元格中的按钮显示,该按钮位于tableview中.
在通用应用程序中处理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];
}
Run Code Online (Sandbox Code Playgroud)
rma*_*ddy 18
它的普遍性无关紧要.popoverPresentationController无论如何,您都可以设置警报控制器.然后它将在所有设备上正确显示.
在这种情况下,您应该为所选行设置sourceViewto tableView和sourceRectto rect.
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:titleToUse message:nil preferredStyle:UIAlertControllerStyleActionSheet];
actionSheet.popoverPresentationController.sourceView = tableView;
actionSheet.popoverPresentationController.sourceRect = [tableView rectForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4196 次 |
| 最近记录: |