gpt4 book ai didi

iphone - iPad 上 UIActionSheet 的问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:35 24 4
gpt4 key购买 nike

我正在制作一个与 iPhone 和 iPad 兼容的应用程序,并且我在操作表中显示了一个选择器,如下所示:

actionSheet = [[UIActionSheet alloc] initWithTitle:@"Day / Month"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];

picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,40,0,0)];
picker.delegate = self;
picker.showsSelectionIndicator = YES;
[actionSheet addSubview:picker];

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet setBounds:CGRectMake(0,0,320,469)];

这适用于 iPhone,但对于具有相同代码且不考虑尺寸不同的 iPad 版本,会出现以下错误:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil'

在这一行:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

我试过 showInView:self.view , self.Window, self.view.superview 但没有...

我想知道是什么导致了这个错误,并且不会让我以同样的方式去做......提前致谢!

最佳答案

操作表在 iPad 上转换为弹出窗口。有两种方法可以显示弹出式广告-

 - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;

据此推测,我认为您可以尝试使用以下方法之一来呈现 action sheet-

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated 
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated

而不是使用 showInView:

关于iphone - iPad 上 UIActionSheet 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7647425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com