Can't resize height contentSizeForViewInPopover of UIViewController in side UINavigationController of UIPopover - ios

I use UINavigationController inside UIPopoverController
-(void)showEditMenuFrom:(UIButton *)button{
if (self.popover) {
[self.popover dismissPopoverAnimated:YES];
self.popover = nil;
}
else {
EditMenuViewController *editMenuViewController = [[EditMenuViewController alloc] initWithNibName:#"EditMenuViewController" bundle:nil];
UINavigationController *actionsNavigationController = [[UINavigationController alloc] initWithRootViewController:editMenuViewController];
actionsNavigationController.delegate = self;
// switch for iPhone and iPad.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:actionsNavigationController];
self.popover.delegate = self;
// CGRect presentFrame = CGRectMake(button.frame.origin.x-43, button.frame.origin.y-10, button.frame.size.width, button.frame.size.height);
[self.popover presentPopoverFromRect:button.frame inView:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentViewController:actionsNavigationController animated:YES completion:^{
NSLog(#"Activity complete");
}];
}
}
}
And I try to resize view inside UIPopover when navigate and these are result:
Root view:
2.Push to other VC
3.Pop back:
You can see the height of root VC can't change back to origin size.
I try to set contentSizeForViewInPopover in viewDidAppear, viewDidLoad and in UINavigationControllerDelegate but no methods work
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(#"Show VIEW %#",viewController);
if ([viewController isKindOfClass:[EditMenuViewController class]]) {
viewController.contentSizeForViewInPopover = CGSizeMake(160.0, 160.0);
} else {
viewController.contentSizeForViewInPopover = CGSizeMake(320.0, 320.0);
}
}
How to solve this problem? Thanks!

I end up my question for someone meet this solution:
First, you need to declare a #property inside the VC which pop back on stack
#property (nonatomic, strong) UIPopoverController *popover;
Then assign it to UIPopoverController in main code
self.popover = [[UIPopoverController alloc] initWithContentViewController:actionsNavigationController];
self.popover.delegate = self;
editMenuViewController.popover = self.popover;
And Finally, setting the size in viewWillAppear of VC you want to resize
-(void)viewWillAppear:(BOOL)animated
{
[self.popover setPopoverContentSize:CGSizeMake(160,160)];
self.contentSizeForViewInPopover = CGSizeMake(160,160);
[super viewWillAppear:animated];
}

Try with bellow example miht be usefull:-
-(void)showEditMenuFrom:(UIButton *)button{
if (self.popover) {
[self.popover dismissPopoverAnimated:YES];
self.popover = nil;
}
else {
EditMenuViewController *editMenuViewController = [[EditMenuViewController alloc] initWithNibName:#"EditMenuViewController" bundle:nil];
UINavigationController *actionsNavigationController = [[UINavigationController alloc] initWithRootViewController:editMenuViewController];
actionsNavigationController.delegate = self;
// switch for iPhone and iPad.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:actionsNavigationController];
self.popover.delegate = self;
popover.popoverContentSize =CGSizeMake(250,200); //Addint this line for setContentsize
[self.popover presentPopoverFromRect:button.frame inView:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentViewController:actionsNavigationController animated:YES completion:^{
NSLog(#"Activity complete");
}];
}
}
}
In EditMenuViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//self.clearsSelectionOnViewWillAppear = NO; //this work if superclass is UITableviewcontroller
self.contentSizeForViewInPopover = CGSizeMake(200,100);
}
-(void)viewWillDisappear:(BOOL)animated
{
self.contentSizeForViewInPopover = CGSizeMake(250,200);
[super viewWillDisappear:YES];
}
ADD
Check some useful similar to your issue:-
Animate popoverContentsize when pushing navigation view controller in popover on iPad
UIPopoverController automatically resizing to max height on pushViewController
push a new tableViewController in a uipopovercontroller causes the popover to be resized
Popover with embedded navigation controller doesn't respect size on back nav

Related

AppDelegate should call the method if the screen orientation has changed

I have a popover, which I present from the TabBarItem thats why I make it in AppDelegate, but I need to reshow popover in new place if the screen orientation has changed. In other places of my app I just use the didRotateFromInterfaceOrientation method, but it doesn't called in AppDelegate. How can I solve this?
I present a popover by this code:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (viewController == [self.objTabBarController.viewControllers objectAtIndex:2])
{
if (self.settingsPopover == nil) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main - iPad" bundle: nil];
SettingsViewController *settingsController = [mainStoryboard instantiateViewControllerWithIdentifier: #"SettingsPopover"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingsController];
self.settingsPopover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
CGSize tabBarSize = self.objTabBarController.tabBar.frame.size;
CGPoint center = [self.window.rootViewController.view convertPoint:self.objTabBarController.tabBar.center fromView:self.objTabBarController.tabBar.superview];
center.x += 105;
center.y -= tabBarSize.height / 2;
CGRect rect = {center, CGSizeZero};
[self.settingsPopover presentPopoverFromRect:rect inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else {
[self.settingsPopover dismissPopoverAnimated:NO];
self.settingsPopover = nil;
}
return NO;
}
}
return YES;
}
You can register a Notification as follow:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleDidChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
Then, implement it in the AppDelegate:
- (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification;
{
NSLog(#"The orientation changed to %#", [notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey]);
}
Enjoy. :)

Show dynamic result in a UIPopoverController

I can't set data inside the viewController "searchController" managed by a UIPopoverController:
in viewDidLoad i have:
searchController = [[PopOverSearchController alloc] initWithNibName:#"PopOverSearchController" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:searchController];
I do a method for call this popover that work fine:
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
searchController.data = data;
[searchController.tableResult reloadData];
CGRect popRect = CGRectMake(self.searchBar.frame.origin.x,
self.searchBar.frame.origin.y +15,
self.searchBar.frame.size.width,
self.searchBar.frame.size.height);
[popoverController presentPopoverFromRect:popRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
[searchController.tableResult reloadData]; was not called: the popup appear (above the search bar )but with an empty table

UINavigationController, how to hide tabbar in second level viewController then show tabbar in third level viewController

here is a piece of my code, but in this way, when I push the third level view controller, the tabbar won't show.
//at first level
SecondLevelViewController *_2vc = [[SecondLevelViewController alloc]initWithNibName:#"SecondLevelViewController" bundle:nil];
_2vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:_2vc animated:YES];
//at second level
ThirdLevelViewController *_3vc = [[ThirdLevelViewController alloc]initWithNibName:#"ThirdLevelViewController" bundle:nil];
_3vc.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:_3vc animated:YES];
// Load the view
AddViewController *aController = [[AddViewController alloc] init];
// Set the view title
aController.title = #"Add View";
// hide tabbar
aController.hidesBottomBarWhenPushed = YES;
// add it to stack.
[[self navigationController] pushViewController:aController animated:YES];
-(void)viewWillAppear: (BOOL)animated
{
[super viewWillAppear:animated];
[self.tabBarController.tabBar setHidden:YES];
}
-(void)viewWillDisappear: (BOOL)animated
{
[super viewWillDisappear:animated];
[self.tabBarController.tabBar setHidden:NO];
}
Instead of setting the values of hidesBottomBarWhenPushed when you initialise the view controllers, you should instead handle the hiding mechanism in the -(void)viewWillAppear:(BOOL)animated in the view controllers instead.
An example of this implementation would be:
In SecondLevelViewController.m
-(void)viewWillAppear:(BOOL)animated
{
[_bottomBar setHidden:YES];
}
In ThirdLevelViewController.m
-(void)viewWillAppear:(BOOL)animated
{
[_bottomBar setHidden:NO];
}

Displaying WEPopover from UIButton instead of UIBarButtonItem

I am using WEPopover in my app to pop up a popover controller containg some buttons,it works when i put wepopover controller action in tabbarIteam but i need to get popover when i click UIButton.How to do this this is my barbuttonitem code for displaying popover.
-(IBAction)_clickbtnAccount:(id)sender
{
if (!self.popoverController)
{
UIViewController *contentViewController = [[pageAccount alloc]initWithNibName:#"pageAccount" bundle:nil];
self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];
self.popoverController.delegate = self;
self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];
[self.popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown)
animated:YES];
[contentViewController release];
}
else
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
}
-(IBAction)_clickbtnAccount:(id)sender
{
if (!self.popoverController)
{
UIButton *senderButton = (UIButton *)sender;
[self.popoverController presentPopoverFromRect:[senderButton frame]
inView:#"pageAccount"
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown)
animated:YES];
}
else
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
}
So you don't want to display a WEPopoverfrom an UIBarButtonItem but from an UIButton, right?!
Just use
- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
instead of
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
and pass in the rect of your UIButton.
Taking your code as an example:
-(IBAction)_clickbtnAccount:(id)sender
{
if (!self.popoverController) {
UIViewController *contentViewController = [[pageAccount alloc]initWithNibName:#"pageAccount" bundle:nil];
self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];
self.popoverController.delegate = self;
self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];
UIButton *senderButton = (UIButton *)sender;
[self.popoverController presentPopoverFromRect:[senderButton frame]
inView:self.view
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown)
animated:YES];
[contentViewController release];
} else {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
}
WEPopover is basically used to show multiple options inside a popover with much control using UITableview.
This is how i use WEPopOver to show popup on a button click
-(void)showPopOver:(id)sender{
if (self.popoverController) {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
PopOverTable *contentViewController = [[PopOverTable alloc] initWithStyle:UITableViewStylePlain];
contentViewController.delegatePopoverItemSelectedDelegate=self;
rectForPopover = [self.view convertRect:btn.bounds fromView:btn];
self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];
if ([self.popoverController respondsToSelector:#selector(setContainerViewProperties:)]) {
[self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
}
self.popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:rectForPopover
inView: self.view
permittedArrowDirections:(UIPopoverArrowDirectionAny)
animated:YES];
}
With the accepted solution I get rotation issues for the WEPopover under iOS 7: Basically it was pointing to a custom button in the UIBarButtonItem on the left of the navigation bar but on rotation the pop up moves to the right side of the screen and stays there on further rotations.

Orientation Problem while using insertSubview

I get an orientation problem while using the following to code to display a view on top of a split view.
[window addSubview:aSplitViewController.view];
[window insertSubview:aViewController.view aboveSubview:aSplitViewController.view];
the plain view has a couple of buttons and labels.
So the problem I am facing is that the first view opens in landscape mode but the labels and buttons on the view are in portrait mode.
UPDATE: Here is some code so if anyone wants to see more details...
In my App Delegate
- (void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
// First tabbbar item
// detail view
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *navDetailView = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
navDetailView.hidesBottomBarWhenPushed = YES;
// root view
rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.detailViewController = detailViewController;
rootViewController.navigationItem.title = #"List";
UINavigationController *navRootView = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
navRootView.hidesBottomBarWhenPushed = YES;
navRootView.navigationBar.barStyle = UIBarStyleBlackTranslucent;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem.title = #"Face Sheet";
splitViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
splitViewController.navigationItem.title = #"Face Sheet";
splitViewController.viewControllers = [NSArray arrayWithObjects:navRootView, navDetailView, nil];
splitViewController.delegate = detailViewController;
splitViewController.hidesBottomBarWhenPushed = YES;
[controllers addObject:splitViewController];
// Second tabbbar item
scoreViewController = [[ScoreCardViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
scoreViewController.tabBarItem.title = #"Score Card";
scoreViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
scoreViewController.navigationItem.title = #"Score Card";
[controllers addObject:scoreViewController];
tabBarController.viewControllers = controllers;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Create tabbar
tabBarController = [[UITabBarController alloc] init];
//tabBarController.delegate = self;
// Set window
[window addSubview:splashController.view];
[window insertSubview:tabBarController.view belowSubview:splashController.view];
[self.window makeKeyAndVisible];
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
return YES;
}
and here is the code in my SplashScreenView
- (IBAction) proceedButtonClick:(id)sender
{
// Initialize loginpopview
PhysicianLoginViewController *loginViewController = [[PhysicianLoginViewController alloc] init];
popOverController = [[UIPopoverController alloc] initWithContentViewController:loginViewController];
popOverController.popoverContentSize = CGSizeMake(350, 200);
popOverController.delegate = self;
// Set a notification to dismiss it later
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(loginViewControllerDone:) name:#"loginViewControllerDone" object:popOverController.contentViewController];
// Present popover
if ([popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
else
{
[popOverController presentPopoverFromRect:CGRectMake(485, 600, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
// Dismiss popview controller and setup the tabbar
- (void)loginViewControllerDone:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Button in content view controller was tapped, dismiss popover...
[self.popOverController dismissPopoverAnimated:YES];
// remove subview
[self.view removeFromSuperview];
// set tabbar
i3EAppDelegate *appDelegate = (i3EAppDelegate *) [[UIApplication sharedApplication]delegate];
[appDelegate makeSplitViewController];
}
It would be great if someone could point out where I am going wrong. I have been stuck with this problem for quite a few days and I have tried everything that comes to my mind...
UIWindow has a subview that it uses for rotations and puts other views inside of that. You need to insert yourself into the root view (or something lower), not the window. Look at -[UIWindow rootViewController].
UIView *rootView = [[[self window] rootViewController] view];
[rootView addSubview:view];
This will work as long as you're using something with a root view controller. This will work as long as rootViewController isn't nil. If you're doing a raw "View Based" application, then it's usually best to pick another view and add your view as its sibling rather than digging through the undocumented hierarchy:
UIView *sibling = ... (some other view)
[[sibling superview] addSubview:view];

Resources