UIAlertController作为ActionSheet在iPad中的大小不正确

时间:2015-06-04 07:06:04

标签: ios objective-c ipad

目前我遇到的问题是在UIAlertController显示UIAlertControllerStyleActionSheet作为首选样式时,添加UIAlertActionStyleCancel按钮会导致显示问题。 显示的_UIPopoverView框架的大小不足以显示整个操作表。

以下是代码: -

- (IBAction)showActionSheet:(UIButton *)sender {
    [self presentActionSheetFromSender:sender withCancelButtonStyel:UIAlertActionStyleCancel];
}



- (void)presentActionSheetFromSender:(UIButton *)sender withCancelButtonStyel:(UIAlertActionStyle)cancelButtonStyle {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TestController" message:@"TestMessage" preferredStyle:UIAlertControllerStyleActionSheet];
    alertController.popoverPresentationController.sourceRect = sender.bounds;
    alertController.popoverPresentationController.sourceView = sender;

    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:cancelButtonStyle handler:^(UIAlertAction *action) {
        [alertController dismissViewControllerAnimated:YES completion:nil];
    }]];

    [self presentViewController:alertController animated:YES completion:nil];
}

所以当前的问题是ActionSheet只显示标题和消息,切断了取消按钮。

2 个答案:

答案 0 :(得分:0)

尝试这个我希望它有助于此..

- (IBAction)btnshare:(id)sender
{

    NSString *cancelTitle = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?@"Cancel" : nil;
    popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing    option:   " delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
             @"Twitter",
             @"Facebook",
             @"Mail",
             @"TextMessage",
             nil];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        // In this case the device is an iPad..
        [popup showFromRect:[(UIButton *)sender frame] inView:self.view animated:YES];
    }
    else
    {
        // In this case the device is an iPhone/iPod Touch.
        [popup showInView:self.view];

    }

    popup.tag = 1;
    [popup showInView:[UIApplication sharedApplication].keyWindow];

}

答案 1 :(得分:0)

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TestController" message:@"TestMessage" preferredStyle:UIAlertControllerStyleActionSheet];

您设置了UIAlertControllerStyleActionSheet,因此UIAlertAction样式UIAlertActionStyleCancel无效。

您可以更改其中一个以修复它。