NSInvalidArgumentException错误。未在UIUserInterfaceIdiomPad下运行

时间:2012-10-04 20:22:02

标签: objective-c ios xcode universal

虽然我理解为什么我会收到错误

'',原因:' - [UIPopoverController initWithContentViewController:]在未在UIUserInterfaceIdiomPad下运行时调用。'

纠正它变得有点棘手。我的弹出只需要在ipad而不是iphone版本上。我省略了iphone if statement的任何代码,但仍然崩溃了。 。假设我必须在iphone上调用一个视图以及它的通用应用程序,我只需在if iphone statement中调用nib,这也不起作用。

 - (IBAction)popZs:(id)sender {  




if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

    if ([popoverController isPopoverVisible]) {
        [popoverController dismissPopoverAnimated:YES];
    } else {

        [self->popoverController setPopoverContentSize: CGSizeMake(601, 571)];

        [popoverController presentPopoverFromRect:((UIButton *)sender).bounds
                                           inView:sender
                         permittedArrowDirections:UIPopoverArrowDirectionUp
                                         animated:YES];

    }



}
else {

    /////using iPhone/////not sure how to handle this spart
     zsTablePop *pop = [[zsTablePop alloc] init];
    pop.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [pop presentModalViewController:pop animated:YES];



}

即使使用if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

,也要保持同样的感觉

创建pop over

.m


#import "ICCircuitDetails.h"
#import "zsTablePop.h"  ///////////////pop over xib/////

 @interface ICCircuitDetails ()



{
zsTablePop *controller;
UIPopoverController *popoverController;
}


 ///////more code/////////////


 - (id)initWithCircuit:(Circuit *)circuit
{


 self = [super initWithCertificate:circuit.distributionBoard.certificate];
if (self) {
    self.circuit = circuit;
    [[NSBundle mainBundle] loadNibNamed:@"ICCircuitDetails" owner:self options:nil];
    self.view.contentSize = CGSizeMake(self.contentView.frame.size.width,    self.contentView.frame.size.height);

 ///////////other code here/////////////////

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) 

    controller = [[zsTablePop alloc] initWithNibName:@"zsTablePop" bundle:nil];
    popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];

1 个答案:

答案 0 :(得分:1)

您的错误消息显示您尝试实例化弹出窗口。代码只是关于呈现它。您还需要处理实例化。