IOS UISplitViewController之 解决 密码框添加之后 调用子视图的转向方法之时 对象为空

在上一篇中  IOS UISplitViewController之 添加启动密码,在添加完 启动密码后,调用此方法:

在 (UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:ButtonItem;  

方法中调用下面的语句,保存 master 的按钮(因为时系统作为参数传递过来的),在手动调用时要用到

profileBarButtonItem = barsplitViewController:

- (void)passcodeViewDidDismiss
{
    UIInterfaceOrientation orientation = self.splitController.interfaceOrientation;
    UIInterfaceOrientation masterFrom = self.masterController.interfaceOrientation;
    UIInterfaceOrientation detailFrom = self.detailController.interfaceOrientation;
    [self.masterController willRotateToInterfaceOrientation:orientation duration:.1];
    [self.detailController willRotateToInterfaceOrientation:orientation duration:.1];
    [self.masterController didRotateFromInterfaceOrientation:masterFrom];
    [self.detailController didRotateFromInterfaceOrientation:detailFrom];
    
    CGFloat deviceHeight = [[UIScreen mainScreen]applicationFrame].size.height;
    if (1024 == deviceHeight) {                     //只有当设备是横屏显示时
        [self splitViewController:splitController willShowViewController:masterController invalidatingBarButtonItem:nil];   // 分割视图在  添加密码框时,启动时不会走此方法,所以需要手动调用
    }
    else
    {
        [self splitViewController:splitController willHideViewController:masterController withBarButtonItem:profileBarButtonItem forPopoverController:self.currentPopover];
    }
}


时,因为 转向方法 早于 
masterController
detailController
的loadView  和 viewDidLoad 等方法,所以 此时 其中的子对象都为空,转向操作不起作用,

解决办法为  为需要转向的  子视图对象 添加get 方法

如下 :

- (RecentsViewController *)recentsController
{
    if (recentsController != nil) {
        return recentsController;
    }
    recentsController = [[RecentsViewController alloc]init];
    return recentsController;
}


就可以啦


但是 如果,子视图对象 为 nib 文件 的IBOutlet 对象的话,此时你如果还想转换位置,

可以

在willRotateToInterfaceOrientation:duration:

方法中将方向存储起来:

DrviceOrientation = toInterfaceOrientation;

然后在viewDidLoad方法中使用 :

如下:

if (UIInterfaceOrientationIsLandscape(DrviceOrientation)) {
        self.topView.frame = kTopLandscape_Frame;
        self.bottomView.frame = kBottomLandscape_Frame;
    }
    else {
        self.topView.frame = kTopPortrait_Frame;
        self.bottomView.frame = kBottomPortrait_Frame;
    }




你可能感兴趣的:(ios,加密,存储)