UIPopoverController is showing on the other button - iphone

When UIButton is tapped to display UIPopovercontroller, it is showing on the other UIbarbuttonitemand it is showing blank black opaque UIPopovercontroller.
Here is my implemented code:
- (IBAction)buttonTapped:(id)sender {
UIButton *btnAction;
BookmarkViewController* bookmarkVC = [[BookmarkViewController alloc] init];
_buttonPopoverController = [[UIPopoverController alloc]
initWithContentViewController:bookmarkVC];
_buttonPopoverController.delegate = self;
CGRect popoverFrame = btnAction.frame;
[_buttonPopoverController setPopoverContentSize:CGSizeMake(320, 355) animated:NO];
//only required if using delegate methods
[_buttonPopoverController presentPopoverFromRect:popoverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}

UIButton *btnAction=(UIButton*) sender;

You are missing to assing sender to btnAction
that is UIButton *btnAction=(UIButton *)sender;
try this,
- (IBAction)buttonTapped:(id)sender {
UIButton *btnAction=(UIButton *)sender;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *bookmarkVC = [storyboard instantiateViewControllerWithIdentifier:#"BookmarkViewController"];
_buttonPopoverController = [[UIPopoverController alloc]
initWithContentViewController:bookmarkVC];
_buttonPopoverController.delegate = self;
CGRect popoverFrame = btnAction.frame;
[bookmarkVC setContentSizeForViewInPopover:CGSizeMake(320, 355)];
//only required if using delegate methods
[_buttonPopoverController presentPopoverFromRect:popoverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}

Your issue is here
[_buttonPopoverController presentPopoverFromRect:popoverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
where presentPopoverFromRect:popoverFrame should be actually the rect of the popover not of the UIButton and also the btnAction has no frame you haven't allocated it also and you are performing CGRect popoverFrame = btnAction.frame;
It should be like
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 300.0, 50.0) inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Hope this helps.

Related

Splash screen with UIActivityIndicatorView loading resources then calling another ViewController

I'm having a hard time trying to do something simple,
I have one viewcontroller that I want to use as a splash screen to the main menu viewcontroller. I can't figure why the modal is not called from the splash.
anybody have idea what is going on?
- (void)viewDidLoad
{
[super viewDidLoad];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0.0, 0.0, 180.0, 180.0);
indicator.center = self.view.center;
[self.view addSubview:indicator];
[indicator bringSubviewToFront:self.view];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
//prepare all resources for app
[indicator startAnimating];
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MainMenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:#"mainMenu"];
mainMenu.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainMenu animated:YES];
}
if I attach an button pressed event with the same code it works fine:
//[btn1 addTarget:self action:#selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
- (void)buttonPressedAction:(id)sender
{
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MainMenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:#"mainMenu"];
mainMenu.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainMenu animated:YES];
}
I changed the viewDidLoad to viewDidAppear and it worked fine. I don't know why though

NavigationController not showing on UIViewController presenting modally

Have a mainviewcontroller and on it have UIToolbar which has a UIBarButtonItem Info which shows UIViewcontroller modally.
Now when pressing Infobutton it is showing UIViewController modally which has UITextView but not showing UINavigationController with Done button.
I am not able to figure it out what i am missing in my code.
This is how i am showing UITextView and NavigationController in UIViewController modally.
#import "ModalViewController.h"
#import <QuartzCore/QuartzCore.h>
#implementation ModalViewController
#synthesize textView;
#synthesize navBar;
#synthesize navigationController;
#synthesize delegate;
-(void)dealloc
{
[textView release];
[navBar release];
[navigationController release];
[super dealloc];
}
- (void) viewDidLoad
{
[super viewDidLoad];
self.title = #"Info";
UINavigationController *navigationController = [[UINavigationController alloc]init];
//initWithRootViewController:viewController];
self.navigationController.navigationBar.tintColor = [UIColor brownColor];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(Done:)] autorelease];
self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)]autorelease];
self.textView.textColor = [UIColor whiteColor];
self.textView.font = [UIFont fontWithName:#"Georgia-BoldItalic" size:14];
//self.textView.delegate = self;
self.textView.backgroundColor = [UIColor brownColor];
self.textView.layer.borderWidth = 1;
self.textView.layer.borderColor = [[UIColor whiteColor] CGColor];
self.textView.layer.cornerRadius = 1;
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.text = #"This is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.
self.textView.editable = NO;
//[self.view addSubview:navigationController.view];
[self.view addSubview: self.textView];
//[navigationController release];
}
And this is how UIViewController presented modally
//Create a final modal view controller
UIButton *modalViewButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[modalViewButton addTarget:self action:#selector(modalViewAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:modalViewButton];
self.navigationItem.rightBarButtonItem = modalBarButtonItem;
- (void) modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
//self.viewController = [[ModalViewController alloc] init];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//ModalViewController *myModalViewController = [[ModalViewController alloc] init];
//UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myModalViewController];
//navigationController.navigationBar.tintColor = [UIColor brownColor];
_viewController = [[ModalViewController alloc] init];
//[navigationController pushViewController:_viewController animated:YES];
[self presentModalViewController:self.viewController animated:YES];
//[self.view addSubview:navigationController.view];
//[navigationController release];
[myModalViewController release];
}
I will appreciate if you can figure out what i m doing wrong or missing in my code.
Thanks a lot.
This seems like a needlessly convoluted way of displaying the new controller. In my apps, I do it like this:
//this function displays (modally) view controller nested inside a navcontroller
- (void) showModalController
{
YourViewController * ecreator = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController * navcontrol = [[UINavigationController alloc] initWithRootViewController: ecreator];
[self presentModalViewController: navcontrol animated:YES];
[navcontrol release];
[ecreator release];
}
Now you want to do the graphical setup (navbar color etc) in the initWithNib and/or viewDidLoad functions of the YourViewController.
#synthesize navigationController;
so navigationController is your class member variable.
in the function
- (void) viewDidLoad
you declare a local variable
UINavigationController *navigationController
Please notice that the second navigationController is different from your member variable navigationController .
So, inside viewDidLoad you need to create object of your member variable navigationController. Not the local variable navigationController.
Do not RE-declare navigationController in viewDidLoad. Instead, create the object using member variable like:
navigationController = [[UINavigationController alloc]init];
Try this, it worked great for me. I had the exact same problem
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#“segue_name"])
{
UINavigationController *nav = [segue destinationViewController];
ExampleViewController *exampleVC = (ExampleViewController *) nav.topViewController;
//Setup any properties here and segue
}
}

how to get a popover frame of specified width and height in ipad

i am using an popover view in my application,when i went through the samples i found how to create a popover view but in the sample code the popover view is getting displayed to whole page. i want the popover frame of specified width and height when i click the button.
-(IBAction) settingsGo:(id) sender{
NSLog(#"Go");
if (self.popoverController == nil)
{
PopOver *lang = [[PopOver alloc]
initWithNibName:#"PopOver" bundle:[NSBundle mainBundle]];
UIPopoverController *popOver =
[[UIPopoverController alloc]initWithContentViewController:lang];
popOver.delegate = self;
[lang release];
self.popoverController = popOver;
[popOver release];
}
CGRect popoverRect = [self.view convertRect:[button frame]fromView:[button superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 50);
[self. popoverController
presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
so what changes i should make in the above code to get a frame of specified size of width and height.
Account is the class to be displayed. popAccount is its instance. buttonA is the button on which after click the popOver will be displayed.
-(void)viewDidLoad
{
popAccount = [[Account alloc] init];
//[popAccount setDelegate:self];
popOverControllerA = [[UIPopoverController alloc] initWithContentViewController:popAccount];
popOverControllerA.popoverContentSize = CGSizeMake(200, 200);
}
-(IBAction)togglePopOverControllerA {
if ([popOverControllerA isPopoverVisible]) {
[popOverControllerA dismissPopoverAnimated:YES];
} else {
[popOverControllerA presentPopoverFromRect:buttonA.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Further ask for any query..
Set popoverController.popoverContentSize to whatever size you want.
In the root view to position
CGRect frame= CGRectMake(0,0, 0, 0);
[self.myPickerPopover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:0 animated:NO];
To size in the view controller contents being displayed in the popover
-(void)viewDidLoad
{
self.contentSizeForViewInPopover = CGSizeMake(750,880);
}

How can I see lastest subView after clicking popover embedded in NavigationView?

When click button, a popoverView embedded in NavigationView appear.
My code is as follows:
-(IBAction)myStuffPOP:(id)sender
{
if(myStuffListViewController ==nil)
{
myStuffListViewController = [[MyStuffListViewController alloc] init];
}
UINavigationController *navcontroller=[[[UINavigationController alloc] initWithRootViewController:myStuffListViewController] autorelease];
// Here we create popover controller.
mystuffPopoverView = [[UIPopoverController alloc] initWithContentViewController:navcontroller] ;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100);
popoverRect.size.height = 40;
[mystuffPopoverView presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[navcontroller setNavigationBarHidden:NO];
}
In NavigationView of PopoverView :
1st subView ---> 2nd SubView ---> 3rd Subview
If I touch 3rd SubView, PopoverView disappears.
My Question is :
When I click button again, I wanna to see lastest View - 3rd SubView not 1st SubView.
Declare UINavigationController *navcontroller; in .h file
Create only onсe navcontroller with your root view controller,
in viewDidLoad method, for example.
- (void)viewDidLoad {
myStuffListViewController = [[MyStuffListViewController alloc] init];
navcontroller=[[UINavigationController alloc] initWithRootViewController:myStuffListViewController]; }
Show UIPopoverController with exist navigation stack
-(IBAction)myStuffPOP:(id)sender {
//Here we create popover controller.
mystuffPopoverView = [[UIPopoverController alloc] initWithContentViewController:navcontroller] ;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100);
popoverRect.size.height = 40;
[mystuffPopoverView presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
[navcontroller setNavigationBarHidden:NO]; }
Don't forget to release objects
- (void)dealloc {
[myStuffListViewController release];
[navcontroller release];
}
No need to create UINavigationController every time. Save it the same way as MyStuffListViewController
if ( myNavigationController == nil )
myNavigationController = [[[UINavigationController alloc] initWithRootViewController:myStuffListViewController] autorelease];

problem with UIPopoverController while navigation

I have UIPopoverController and two ViewController class.
SaveProject and ProjectName is viewController class.
When i am clicking save project. its give me navigation and load another view.
But the UIPopoverController size height is getting increased to the total view size.
Can any one help me out with this..
I am attaching here code:
-(void)createSaveAndCloseView{
saveAndCloseViewController = [[WGSaveAndCloseViewController alloc]init];
[saveAndCloseViewController.view setFrame:CGRectMake(0, 0, 310, 171)];
saveAndCloseViewController.navigationItem.title = #"Save or Discard";
UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(cancelAction:)];
saveAndCloseViewController.navigationItem.rightBarButtonItem = cancel;
[cancel release];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:saveAndCloseViewController];
saveAndClosePopupView = [[UIPopoverController alloc] initWithContentViewController:navControl];
saveAndClosePopupView.delegate = self;
saveAndClosePopupView.popoverContentSize = CGSizeMake(312, 160);
saveAndCloseViewController.view.contentMode = UIViewContentModeScaleAspectFill;
[saveAndClosePopupView presentPopoverFromRect:[saveAndClose bounds] inView:saveAndClose permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[navControl release];
}
-(void)saveProjectClick:(id)sender{
if (saveProject.tag == tagSave) {
WGNameProjectViewController *nameProjectViewController = [[WGNameProjectViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:nameProjectViewController animated:YES];
nameProjectViewController.navigationItem.title = #"Name Project";
[nameProjectViewController release];
nameProjectViewController = nil;
}
}
You just need to add something like:
self.preferredContentSize = <view size>
to the viewWillAppear: method in each of your view controllers that are displayed in the popover.