Gopi Krish
Gopi Krish

Reputation: 71

UIPopoverview for iPhone,iOS 7

enter image description here

I need popover view. i followed this instructions.

Init: Create two UIViewController in storyboard.

lets say FirstViewController which is normal and SecondViewController Which we make Popup. Model Segue: Put UIButton In FirstViewController and create a segue on this UIButton to SecondViewController as model segue.

Make Transparent: Now selet UIView (UIView Which is created by default with UIViewController) of SecondViewController and change its background color to clear color.

Make background Dim: Add a UIImageView in SecondViewController which cover hole screen and sets its image to some dimmed semi transparent image. You can get a sample from here : UIAlertView Background Image

Display Design: Now Add a UIView and make and kind of design you want to show. Here I have shown screen shot of my storyboard.

Here I have add segue on login button which open SecondViewController as popup to ask username and password

Important: Now that main step. We want that SecondViewController dont hide FirstViewController completely. We have set clear color but this is not enough. By default it add black behind model presentation So we have to add one line of code in viewDidLoad of FirstViewController. You can add it at other place also but it should run before segue.

[self setModalPresentationStyle:UIModalPresentationCurrentContext];

Dismiss: When to dismiss is depend on you. This is a model presentation so to dismiss we do what we do for model presentation:

[self dismissViewControllerAnimated:YES completion:Nil];

But am USING NAVIGATION CONTROLLER,, for that transparent background is not coming?????

Kindly help me..!!!! My screen shot is below.

Upvotes: 1

Views: 431

Answers (2)

Anbu.Karthik
Anbu.Karthik

Reputation: 82766

create one view controller in freeform mode just like following image

enter image description here

in your first view controller add the one UIButton just like the following image

enter image description here

in your first view controller.h add the following line

#import "UIPopoverController+iPhone.h"


@interface first view controller : UIViewController<UIPopoverControllerDelegate>


@property (nonatomic,strong) UIPopoverController *popOver;

@property (strong, nonatomic) IBOutlet UIButton *popbtn;

in your first view controller.m add the following line to the button action method

 - (IBAction)popButton:(UIButton *)sender
{

UILabel *showlblView=[[UILabel alloc]init];
showlblView.frame=CGRectMake(10, 10, 250, 40);

showlblView.text=@"Gopi";
showlblView.textColor=[UIColor whiteColor];
showlblView.textAlignment=NSTextAlignmentCenter;

final *vc=[[final alloc] init];



[vc.view addSubview:showlblView];

self.popOver=[[UIPopoverController alloc]initWithContentViewController:vc];

[self.popOver setPopoverContentSize:CGSizeMake(300, 200)];

CGRect popoverframe=CGRectMake(self.popbtn.frame.origin.x, self.popbtn.frame.origin.y, self.popbtn.frame.size.width, self.popbtn.frame.size.height);
[self.popOver presentPopoverFromRect:popoverframe inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];



}

here ur NSObjet class file UIPopoverController+iPhone.h

.h file

#import <UIKit/UIKit.h>

@interface UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled;
@end

.m file

#import "UIPopoverController+iPhone.h"

@implementation UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled {
return NO;
}
@end

the full project code is available at the following link :

https://www.sendspace.com/file/ktie4t

Upvotes: 1

aquarium_moose
aquarium_moose

Reputation: 355

i had the same problem and didn't find solution how to solve it with segue on storyboard, but programmatically it's work fine, when i presenting second controller on first controller (that pushed with navigationViewController). if it's not critical for you, try this:

+ (void)showWithParent:(UIViewController *)parentController {
    static SomeViewController *singleton = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        singleton = [storyboard instantiateViewControllerWithIdentifier:@"SomeViewControllerID"];
    });
    [parentController presentViewController:singleton animated:YES completion:nil];
}

or just:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SecondViewController *secondController = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewControllerID"];
[firstController presentViewController:secondController animated:YES completion:nil];

Upvotes: 0

Related Questions