How to close a container view

890 views Asked by At

I'am working on an iOS project with xcode 5. I needed to show an option table in a pop-up, hence I used a container view and called it as a pop-up through segue. Now the problem is I want to close (not merely disappear) the container view as soon as I select a row inside it. Please guide me how to achieve it.Thanks in advance.

2

There are 2 answers

0
User6391 On BEST ANSWER

I finally found a solution to this , its not the feasible solution but saved me from bringing major changes in my project. What I did is -

I used unwind segue to pass back the value from child pop-up container to the main controller.For this I introduced two methods first one was: prepareForSegue method in container view controller-

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"CommentOptionToComments"])
{

    APMCommentsViewController *objCommentController=(APMCommentsViewController *)segue.destinationViewController;
    for(APMOption *obj in self.optionList)
    {
        if(obj.IsAnswer)
        {
            NSString *dataToPassBack=[NSString stringWithFormat:@"%d",obj.Number];
            self.passBackToParent=dataToPassBack;
        }
    }
    NSLog(@"Return to parent");
}
}

another one was unwindSegue method in the ParentViewController -

-(IBAction)unwindToList:(UIStoryboardSegue *)segue
{
    //get the value from the segue and use it as per your requirement
    APMCommentsOptionViewController *source=[segue sourceViewController];
    self.lblHiddenResponse.text=source.passBackToParent;
}

but don't forget to declare the unwind segue in your ParentViewController.h file.

Now what I did is connected my prototype cell to the unwind segue in the storyboard and gave the unwindsegue an identifier name(present in Utility Area)

But the problem was that the unwind segue was called before didSelectRowAtIndexPath was called as a result although the pop up was able to close it self but was unable to send the desired value to the ParentViewController. For this I this I just called the prepareForSegue again in the method didSelectRowAtIndexPath, with syntax such as -

[self performSegueWithIdentifier:@"CommentOptionToComments" sender:self];

As I said its not a feasible solution but this finally solved my problem, but it would have been simpler if I would have used UIPopOverController.

6
thatzprem On

Using pop up instead of UIAlertView is a recommended approach. But if the requirement demands to use popup view, You can simple show/hide the view of the container view controller!