1

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.

User6391
  • 15
  • 6
  • Can you post some code? To "close" a container view wouldn't you just remove it from the superview? Like `[containerView removeFromSuperview]` – rfj001 Nov 10 '14 at 06:30
  • @rfj001 which set of code do expect me to post? let me explain you in an elaborated way:[Please correct me if I'm wrong] I'm using a delegate method to get the value from the container view to the main view.I debugged and found out that the implementation of the delegate is being called at the time when a main view is about to end, which gave me an intuition that if i'll be able to end the container view then at merely a touch then it will be called at the expected time. And I would be able to close the pop-up as well( which is one of my requirement. – User6391 Nov 10 '14 at 08:15
  • I'm not using an xib file so if u can let me know what is the syntax for adding a container view to superview without using xib or nib that will be kind of you – User6391 Nov 10 '14 at 08:25

2 Answers2

0

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!

thatzprem
  • 4,697
  • 1
  • 33
  • 41
0

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.

User6391
  • 15
  • 6