行动表适用于iPhone,但是当我在iPad上试用它时,它无法正常工作。对此有何解决方案?
我的代码如下:
-(void)setUpAlertCtrl{
self.alertCtrl=[UIAlertController alertControllerWithTitle:@"Select Image"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
}
答案 0 :(得分:2)
试试这个
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"Your message" preferredStyle:UIAlertControllerStyleActionSheet];
// Remove arrow from action sheet.
[alertController.popoverPresentationController setPermittedArrowDirections:0];
//For set action sheet to middle of view.
CGRect rect = self.view.frame;
rect.origin.x = self.view.frame.size.width / 20;
rect.origin.y = self.view.frame.size.height / 20;
alertController.popoverPresentationController.sourceView = self.view;
alertController.popoverPresentationController.sourceRect = rect;
[self presentViewController:alertController animated:YES completion:nil]; }
}
答案 1 :(得分:1)
Plz使用此代码它会对你有所帮助 在ipad中,您必须将操作表设置为popover presentation
UIAlertController *alertController=[UIAlertController alertControllerWithTitle:nil message:@"Select Sorting Type" preferredStyle:(UIAlertControllerStyleActionSheet)];
UIAlertAction *Date_action=[UIAlertAction actionWithTitle:@"Date" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//action on click
}];
UIAlertAction *title_action=[UIAlertAction actionWithTitle:@"Title" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//action on click
}];
UIAlertAction *cancel_action=[UIAlertAction actionWithTitle:@"Cancel" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
//action on click
}];
[alertController addAction:Date_action];
[alertController addAction:title_action];
[alertController addAction:cancel_action];
if (Is_IPad) {
UIPopoverPresentationController *popPresenter = [alertController
popoverPresentationController];
//provide source view to actionsheet as popover presentation
popPresenter.sourceView = sender;
popPresenter.sourceRect = sender.bounds;
[self presentViewController:alertController animated:YES completion:nil];
}else{
[self presentViewController:alertController animated:YES completion:nil];
}