【问题标题】:iPad Won't Load Modal ViewiPad 不会加载模态视图
【发布时间】:2011-08-16 23:55:40
【问题描述】:

加载模式视图时出现此错误。

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x72785a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aboutTableView.'

它在 iPhone 上运行得非常好,但我在 iPad 上遇到了这个问题。

- (IBAction)showOptionsMenu
{
    self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    self.optionsNavController.modalPresentationStyle = UIModalPresentationFormSheet;
    self.optionsNavController.modalInPopover = YES;
    [self presentModalViewController:self.optionsNavController animated:YES];
}

更新:

这可行,但没有显示 UIButton:

MoreViewController *svc = [[[MoreViewController alloc] init] autorelease];
optionsNavController= [[UINavigationController alloc] initWithRootViewController:svc];
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.optionsNavController.modalPresentationStyle = UIModalPresentationFormSheet;
self.optionsNavController.modalInPopover = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(dissmissView)];
self.optionsNavController.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];
[self presentModalViewController:self.optionsNavController animated:YES];

【问题讨论】:

    标签: objective-c cocoa-touch ipad uiviewcontroller modalviewcontroller


    【解决方案1】:

    这是为两种设备启动模式视图的好方法:

    #define IDIOM   UI_USER_INTERFACE_IDIOM()
    #define IPAD    UIUserInterfaceIdiomPad   
    
    SomeViewController *svc = [[[SomeViewController alloc] init] autorelease];
    if ( IDIOM == IPAD ) {
        UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:svc];
        [controller setModalPresentationStyle:UIModalPresentationFormSheet];
        [controller setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentModalViewController:controller animated:YES];
        [controller release];
    } else {
        /*  or you can present the view as modal:  */
        [self.navigationController pushViewController:svc animated:YES];
    }
    

    SomeViewController

    -(void)viewDidLoad 
    {
        [super viewDidLoad];
    
        if ( IDIOM == IPAD ) {
            UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                                         target:self action:@selector(dismiss)] autorelease];
            self.navigationItem.leftBarButtonItem = doneButton;
        }
    }
    -(void)dismiss
    {
        [self dismissModalViewControllerAnimated:YES];
    }
    

    【讨论】:

    • 这样做可行,但 UIButton 不会显示以将其关闭。请检查更新的代码。
    • 嗯,不。您需要在SomeViewControllerviewDidLoad 方法中添加UIBuarButtonItem,并将其连接到[self dismissModalViewControllerAnimated: YES];
    【解决方案2】:

    您是否为 iphone/ipad 使用不同的 xib?

    如果是这样,请检查您的 iPad 版本中的连接,可能存在您尚未删除的处理连接。

    【讨论】:

    • 我从中发出调用的 NIB 不同,但加载到 optionsViewController 中的 VC 是相同的。已经有 3 个小时了,我无法弄清楚。
    • 所以要澄清self.optionsNavController iPhone/iPad 只使用一个 xib 还是每个都使用一个 xib?编译时是否有任何警告,例如是.m中合成的aboutTableView属性
    猜你喜欢
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多