我正在为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版本而言,不同尺寸的用户会给我以下错误:
* 由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'参数无效 满足:查看!= nil'
在这一行:
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
我尝试过showInView:self.view,self.Window,self.view.superview但没有...
我想知道是什么给出了这个错误,并且不会让我以同样的方式做到这一点......提前感谢!
答案 0 :(得分:6)
操作表将转换为iPad上的弹出窗口。有两种方法可以显示弹出窗口 -
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
从这里猜测,我认为你可以尝试使用以下方法之一来展示行动表 -
- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated
而不是使用showInView:
。