UIPopover crashing from UIButton - iphone

I'm presenting a UIPopover from a UIButton but my app is crashing at line [popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];
- (IBAction)birthdayButtonClicked:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];
UIDatePicker *datePicker = [[UIDatePicker alloc]init];
datePicker.frame = CGRectMake(0, 44, 320, 300);
[popoverView addSubview:self.view];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
UIButton *button = (UIButton *)sender;
[popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];
[popoverView release];
[popoverContent release];
}

It is not a good idea to add self.view as subview. UIView object can be displayed only once in every current mooment, you cannot show popover with content as self.view in self.view. If you really need to perform this task then try to make copy of required views.

Change the inView to self.view. inView means in which UIView you want to present popover.
presentPopoverFromRect:[button bounds] inView:**self.view** permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];

Related

supporting iphone 5 screen size

Note: Everything worked fine on the older screen sizes however on the new iphone screens (640x1136) things are way to far down
here is the App Delegate initing and showing myRootViewController
myRootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:[NSBundle mainBundle]];
[myRootViewController.view setFrame:[[UIScreen mainScreen] applicationFrame]];
//NSLog(#"rootviewcontroller1 frame %#", NSStringFromCGRect(myRootViewController.view.frame));
//OUTPUTS: {{0, 0}, {320, 460}}
[window addSubview:myRootViewController.view];
The RootViewController sets the frame for the 'navigationController' and a few other views before adding them to its view.
//NSLog(#"ogtest rootviewcontroller frame2 %#", NSStringFromCGRect(self.view.frame));
//OUTPUTS: {{0, 20}, {320, 548}}
[navigationController.view setFrame:CGRectMake(0, 0, 320,528)];
//I have tried multiples variations including not setting it.
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[loadingView setBackgroundColor:[UIColor clearColor]];
UILabel *_loadingLable = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 20.0f)];
_loadingLable.backgroundColor = [UIColor clearColor];
_loadingLable.textColor = [UIColor whiteColor];
_loadingLable.text = #"Loading...";
[_loadingLable setCenter:CGPointMake(181.0f, 240.0f)];
activityIndicatior = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityIndicatior setCenter:CGPointMake(120.0f, 240.0f)];
RoundedView *_roundedRectangle = [[RoundedView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 140.0f, 50.0f) roundedCorner:RoundedCornersTypeALL];
_roundedRectangle.center = CGPointMake(160.0, 240.0);
_roundedRectangle.rectColor = [UIColor blackColor];
_roundedRectangle.alpha = 0.7;
[loadingView addSubview:_roundedRectangle];
[loadingView addSubview:activityIndicatior];
[loadingView addSubview:_loadingLable];
[_loadingLable release];
[_roundedRectangle release];
[loadingView setHidden:YES];
[self.view addSubview:[navigationController view]];
[self.view addSubview: loadingView];
You can see from the image below that the grey bar is there for the nav bar. The text "Tuesday 30 Apr...." with the arrow buttons should occupy that grey area and not 2 cells from the top.
If you find yourself setting the frame of your navigation controller / navigation bar, you're doing something wrong.
Most of the time, you don't even need to set the frame of your view controller's view either.
Your app delegate needn't be any more complicated than this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
[[self window] setRootViewController:[[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}
It will most likely be a setting in your RootViewController nib. For the first view in the "Objects" list on the left, you have probably set the Top Bar property.
I ended up creating separate xib files with
_iPhone_Retina
at end of the file name
Which also called for statements like this
if (IS_IPHONE_RETINA) {
View = [[View alloc] initWithNibName:#"View_iPhone_Retina" bundle:[NSBundle mainBundle]];
}else{
View = [[View alloc] initWithNibName:#"View" bundle:[NSBundle mainBundle]];
}
and IS_IPHONE_RETINA is defined in the projectname.pch file as
#define IS_IPHONE_RETINA ([[UIScreen mainScreen] bounds].size.height == 568 )

uitabelview in uipopoverview

Can any one please give me reference or tutorial for how to include uitabelview in uipopopover view Controlelr with detail view controller,Please do the needfully, Thanks in advance
Update:
- (IBAction) useCameraRoll: (id)sender
{
if([self.popoverController isPopoverVisible])
{
[self.popoverController dismissPopoverAnimated:YES];
return;
}
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 102)];
popoverView.backgroundColor = [UIColor blackColor];
UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 140, 102)];
tblViewMenu.delegate = self;
tblViewMenu.dataSource = self;
tblViewMenu.rowHeight = 32;
[popoverView addSubview:tblViewMenu];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(140, 102);
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the toolbar button which was pressed
[self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 133, 29)
inView:gal permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Please try to google your Query before posting here.
You can find one tutorial here
http://iphoneapp-dev.blogspot.in/2010/11/how-to-insert-uitableview-in.html

Why is UIPopoverController so tall?

I have the following code to open a 320px x 320px UIPopoverController, but for some reason the popover is much taller than it should be - about twice the height that I specified (320px).
What's gone wrong?
colorPicker = [[RSColorPickerView alloc] initWithFrame:CGRectMake(20.0, 20.0, 320.0, 320.0)];
[colorPicker setDelegate:self];
[colorPicker setBrightness:1.0];
[colorPicker setCropToCircle:YES];
[colorPicker setBrightness:1.0];
[colorPicker setBackgroundColor:[UIColor clearColor]];
UIColor * aColor = [UIColor colorWithRed:0.803 green:0.4 blue:0.144 alpha:1];
[colorPicker setSelectionColor:aColor];
UIView *newview = [[UIView alloc] initWithFrame:CGRectMake(20.0, 20.0, 320.0, 320.0)];
[newview addSubview:colorPicker];
UIViewController *newviewcontroller = [[UIViewController alloc] init];
[newviewcontroller setView:newview];
UIPopoverController *newpopover =
[[UIPopoverController alloc] initWithContentViewController:newviewcontroller];
newpopover.delegate = self;
[self.colourController setPopoverContentSize:CGSizeMake(320, 320)];
self.colourController = newpopover;
[self.colourController presentPopoverFromRect:CGRectMake(149, 540, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
You need to set the popoverContentSize on the view controller being presented in the popover. You are setting it on the wrong view controller.
newpopover.delegate = self;
self.colourController = newpopover;
[self.colourController setPopoverContentSize:CGSizeMake(320, 320)];
You were doing these last two lines out of order.

UIDatePicker in UIActionSheet on iPad

In the iPhone version of my app, I have a UIDatePicker in a UIActionSheet. It appears correctly. I am now setting up the iPad version of the app, and the same UIActionSheet when viewed on the iPad appears as a blank blank box.
Here is the code I am using:
UIDatePicker *datePickerView = [[UIDatePicker alloc] init];
datePickerView.datePickerMode = UIDatePickerModeDate;
self.dateActionSheet = [[UIActionSheet alloc] initWithTitle:#"Choose a Follow-up Date"
delegate:self cancelButtonTitle:nil
destructiveButtonTitle:nil otherButtonTitles:#"Done", nil];
[self.dateActionSheet showInView:self.view];
[self.dateActionSheet addSubview:datePickerView];
[self.dateActionSheet sendSubviewToBack:datePickerView];
[self.dateActionSheet setBounds:CGRectMake(0,0,320, 500)];
CGRect pickerRect = datePickerView.bounds;
pickerRect.origin.y = -95;
datePickerView.bounds = pickerRect;
I ended up creating a separate segment of code for the iPad Popover:
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];
datePicker.frame = CGRectMake(0, 44, 320, 300);
[popoverView addSubview:toolbar];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);
//create a popover controller
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[popoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];

Change pop-over contentsize using navigationcontroller

I want to show a popover with a custom contentsize.
I can do it doing like so
UINavigationController* popoverContent = [[UINavigationController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 800, 800)];
popoverView.backgroundColor = [UIColor blueColor];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(55, 55);
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[pop presentPopoverFromRect:CGRectMake(80.0, 210.0, 160.0, 40.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
but if I change the content to :
popoverContent.viewControllers = [NSArray arrayWithObject:myViewController];
the
popoverContent.contentSizeForViewInPopover = CGSizeMake(55, 55);
the size doesn't change at all.
How can I change the content size while using the navigation controller?
Thanks
Explicitly changing the popovers size works:
[self.popoverController setPopoverContentSize:myView.size animated:YES];
But I agree that contentSizeForViewInPopover should work. It doesn't for me anyway.