HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了uikit – UIActionSheet多选可能iOS8 – 不会删除UIWindow大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_419_6@ 我遇到了一些奇怪的iOS8行为,我不知道如何处理它.对我来说似乎是一个错误.也许你对解决方法有个好主意.

重现@L_674_4@:创建一个至少有两个选项的UIActionSheet.在iOS8中,您可以一次选择多个选项.只需触摸em:在设备和模拟器上工作.这可能也发生在糟糕的瞄准.

委托@L_674_4@

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonATindex:(NSInteger)buttonIndex;

将被召唤两次.如果它会停在这里这很容易:只需忽略第二个委托调用.问题是_UIAlertControllerShimPresenterWindow永远不会被解雇,这会导致UI阻塞,因为我们的UIApplication的窗口没有收到任何触摸事件.如果你跑

po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]

在调试模式下,您将获得以下输出

<_UIAlertControllerShimPresenterWindow: 0x7bf5a3d0; frame = (0 0; 320 568); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x7bf5af80>; layer = <UIWindowLayer: 0x7bf5a620>>
    | <UIView: 0x7bf5c460; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7bf5c3f0>>

委托@L_674_4@

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex

永远不会被称为.

使用脏兮兮的黑客重置UIApplication的UIWindow:

[[(MyApplicationDelegate *) [UIApplication sharedApplication].delegate window] makeKeyAndVisible];

不起作用.你对如何解决这个问题有任何其他想法吗?

要重现,只需将以下ViewController放入UINavigationController,你就会遇到问题……万一你不相信我:

#import "ViewController.h"

@interface ViewController () <UIActionSheetDelegate>

@end

@implementation ViewController

- (void)loadView
{
    self.view = [[UIView alloc] initWithFrame: CGRectZero];
    self.view.BACkgroundColor = [UIColor whiteColor];

    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithtitle:@"ActionSheet" style:UIBarButtonItemStylePlain target:self action:@SELEctor(buttonTouchUpInside:)];

    self.toolbarItems = @[buttonItem];
    [self.navigationController setToolbarHidden: NO];
}

- (void)viewDidLoad 
{
    [super viewDidLoad];
    // Do any additional setup after loading the view,typically from a nib.
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark Target Action

- (IBACtion)buttonTouchUpInside:(id)sender
{
    UIActionSheet *aSheet = [[UIActionSheet alloc] initWithtitle:@"Choose an option" delegate:self cancelButtontitle:nil destructiveButtontitle:nil otherButtontitles:@"Option 1",@"Option 2",@"Option 3",@"Option 4",nil];

    [aSheet showFromToolbar: self.navigationController.toolbar];
//    [aSheet showInView: self.view]; // doesn't make any difference
}

#pragma mark UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonATindex:(NSInteger)buttonIndex
{
    NSLog(@"Clicked at button index %lu",(unsigned long) buttonIndeX);
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Did dismiss with button index %lu",(unsigned long) buttonIndeX);
}

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Will dismiss with button index %lu",(unsigned long) buttonIndeX);
}

@end

解决方法

我相信解决这个问题的最好@L_674_4@是在iOS 8中使用UIAlertController而不是UIActionSheet.

以下是如何以适用于iOS 8或iOS 7的方式实现它的示例:

- (IBACtion)buttonCallingActionSheetPressed:(UIBarButtonItem *)sender
{
    id alertControllerClass = NSClassFromString(@"UIAlertController");

    if (alertControllerClass)
    {
        UIAlertAction *sheetAction = nil;
        UIAlertController *actionSheetController = [UIAlertController alertControllerWithtitle:nil
                                                                                       message:nil
                                                                                preferredStyle:UIAlertControllerStyleActionSheet];

        sheetAction = [UIAlertAction actionWithtitle:@"Do something"
                                          style:UIAlertActionStyleDefault
                                        handler:^(UIAlertAction *action) {
                                            [self actionSheetSELEctedIndex:0];
                                        }];
        [actionSheetController addAction:sheetAction];

        sheetAction = [UIAlertAction actionWithtitle:@"Cancel"
                                          style:UIAlertActionStyleCancel
                                        handler:^(UIAlertAction *action) {
                                            [self actionSheetSELEctedIndex:1];
                                        }];
        [actionSheetController addAction:sheetAction];

        [self presentViewController:actionSheetController animated:YES completion:nil];
    }
    else
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithtitle:nil
                                                                 delegate:self
                                                        cancelButtontitle:@"Cancel"
                                                   destructiveButtontitle:nil
                                                        otherButtontitles:@"Do something",nil];
        [actionSheet showFromToolbar:self.navigationController.toolbar];
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonATindex:(NSInteger)buttonIndex
{
    [self actionSheetSELEctedIndex:buttonIndex];
}

- (void)actionSheetSELEctedIndex:(NSInteger)SELEctedAction
{
    // Your logic goes here
}

大佬总结

以上是大佬教程为你收集整理的uikit – UIActionSheet多选可能iOS8 – 不会删除UIWindow全部内容,希望文章能够帮你解决uikit – UIActionSheet多选可能iOS8 – 不会删除UIWindow所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。