Question

I'm trying to write iPad app.

I have UIViewController as parentViewController (full screen) for masterView and detailView (my handmade splitView). Also I have a separate view (for example moreDetailView) with class and xib, which I would like to show as modal.

masterView has UITableView and detailView has UICollectionView. Both of them has own classes and xib. In detailView there are several items.

In my didSelectItemAtIndexPath: of detailView I would like to show moreDetailView.

So, how can I do that? And how to show it in parentViewController, but NOT in detailView.

Hope my question is understandable.

Was it helpful?

Solution

The code below will present your controller in a modal formsheet (you can change this with the setModalPresentationStyle) on the top of your splitView.

- (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
    }]; }

OTHER TIPS

You are initializing your masterview and detailview in parentview. To access the parentcontroller you can declare a property in detailcontroller as

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.

- (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
    }];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top