简体   繁体   English

如何在“ parentViewController”中显示模式视图?

[英]How to present modal view in “parentViewController”?

I'm trying to write iPad app. 我正在尝试编写iPad应用程序。

I have UIViewController as parentViewController (full screen) for masterView and detailView (my handmade splitView). 我有UIViewController作为masterViewdetailView (我的手工splitView)的parentViewController (全屏)。 Also I have a separate view (for example moreDetailView ) with class and xib, which I would like to show as modal. 另外,我有一个单独的视图(例如moreDetailView ),其中包含class和xib,我希望将其显示为模态。

masterView has UITableView and detailView has UICollectionView . masterView具有UITableViewdetailView具有UICollectionView Both of them has own classes and xib. 他们两个都有自己的类和xib。 In detailView there are several items. detailView中有几项。

In my didSelectItemAtIndexPath: of detailView I would like to show moreDetailView . 在我的detailView的 didSelectItemAtIndexPath:中 ,我想显示moreDetailView

So, how can I do that? 那么,我该怎么做呢? And how to show it in parentViewController , but NOT in detailView . 以及如何在parentViewController中显示它,而不是detailView中显示它。

Hope my question is understandable. 希望我的问题是可以理解的。

You are initializing your masterview and detailview in parentview . 要初始化您的masterviewdetailviewparentview To access the parentcontroller you can declare a property in detailcontroller as 要访问parentcontroller你可以声明在属性detailcontroller作为

UIViewController *parent;

and while initializing you can do 在初始化时,您可以

detailController.parent=self;

and while showing modal you can do 在显示模态时,您可以执行

[parent presentModal]; //instead of [self presentModal];

I hope above works for you, you will need to correct the syntax though. 希望以上对您有用,但是您将需要纠正语法。

The code below will present your controller in a modal formsheet (you can change this with the setModalPresentationStyle) on the top of your splitView. 下面的代码将在splitView顶部的模式表单中显示您的控制器(您可以使用setModalPresentationStyle进行更改)。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
    [moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
    [moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

    [self presentViewController:moreDetailViewController animated:YES completion:^{
        //stuff you want to do after the viewController has been presented
    }]; }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
    [moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
    [moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

    [self presentViewController:moreDetailViewController animated:YES completion:^{
        //stuff you want to do after the viewController has been presented
    }];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM