2

I have main dashboard (UITableViewController) and once i sign in i need to show this page with a welcome message which am showing using a UIViewController.

How can i show this popup from my ViewDidAppear() method ?

Am using following code and its not working

  -(void)viewDidAppear:(BOOL)animated{
        popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
        [popupObj setModalPresentationStyle:UIModalPresentationCurrentContext];
    }

please help me..

i saw couple of stackoverflow links

Update

When i change my code to this one

-(void)viewDidAppear:(BOOL)animated{
    popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
   // [popupObj setModalPresentationStyle:UIModalPresentationCurrentContext];
    popupObj.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    popupObj.modalTransitionStyle = UIModalPresentationPopover;
    [self presentViewController:popupObj animated:YES completion:nil];
}

Now i can see my UIViewController coming as popup but now UIViewController coming as full screen view.

But i need only this frame (320 , 320)

Community
  • 1
  • 1
Bangalore
  • 1,572
  • 4
  • 20
  • 50

4 Answers4

1
popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
popupObj.view.frame = CGRectMake(20, 200, 280, 168);
[self.view addSubview:popupObj.view];
[self addChildViewController:popupObj];

You can add UIViewController as subview and set it's frame so it will look like popup. Hope this will help you.

Vivek Shah
  • 430
  • 5
  • 22
1

I have two way,maybe not good, but work at most of time.

First,when the second view controller appear, show a screen shot of the first view controller. like this:

- (void)setBackGround {
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, [UIScreen mainScreen].scale);
    [self.presentingViewController.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.layer.contents = (__bridge id)(image.CGImage);
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (!_isShown) {
        _isShown = YES;
        [self setBackGround];
    }
}

Do't forget set "_isShown = NO" when init.

Second: you can only init a view, and show it on a view controller with animation. code at :http://blog.moemiku.com/?p=101

I have update a example on the blog. Direct download url the gif

wudijimao
  • 53
  • 6
0

Your code creates the view controller and sets its presentation style, but doesn't actually present it. For that to happen you need this line after the two you have right now:

[self presentViewController:popupObj animated:true completion:nil];
TwoStraws
  • 12,862
  • 3
  • 57
  • 71
0

Please set navigation controller on your rootviewcontroller :

 -(void)viewDidAppear:(BOOL)animated
 {  
      popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
      [self.navigationController presentViewController:popupObj animated:YES completion:nil];

  }

Or

  -(void)viewDidAppear:(BOOL)animated
  {  
     popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
        [self.view addSubview:popupObj.view];
  }
Akhilrajtr
  • 5,170
  • 3
  • 19
  • 30
Nikunj5294
  • 391
  • 3
  • 14