兼容ipad的 UIAlertController
-(void)showSheet:(SYUser *)user IndexPath:(NSIndexPath *)indexPath{
SYUser *loginUser=[SYUser sharedLoginUser];
if (loginUser.userRole !=UserRoleEosAdmin) {
return;
}
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle: UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WYLocalizedString(@"co_cancel", @"") style:UIAlertActionStyleCancel handler:nil];
WS(ws)
UIAlertAction *archiveAction=[UIAlertAction actionWithTitle:WYLocalizedString(@"co_delete", @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[ws userDelete:user];
}];
NSString *frozenTitle=@"";
if (user.status==2) {
frozenTitle=[NSString stringWithFormat:@"%@",WYLocalizedString(@"co_frozen", @"")];
}else{
frozenTitle=[NSString stringWithFormat:@"%@",WYLocalizedString(@"co_unfreeze", @"")];
}
UIAlertAction *frozenAction = [UIAlertAction actionWithTitle:frozenTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[ws doFrozen:user];
}];
[alertController addAction:frozenAction];
if (user.status==1) {
[alertController addAction:archiveAction];
}
[alertController addAction:cancelAction];
//核心代码. 兼容ipad
if ([SYAboutDevice currentDeviceType] == UIUserInterfaceIdiomPad) {
CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:indexPath];
CGRect rectInSuperView = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];
UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController];
popPresenter.sourceView =[self.tableView superview];
popPresenter.sourceRect =rectInSuperView;
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:alertController animated:YES completion:nil];
}else{
[self presentViewController:alertController animated:YES completion:nil];
}
}
判断设备是ipad 还是iphone
+(UIUserInterfaceIdiom)currentDeviceType{
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad){
return UIUserInterfaceIdiomPad;
}else{
return UIUserInterfaceIdiomPhone;
}
}
网友评论