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.
Related
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
in ipad the select tag is showed in pop up in a widget wheel. I want to use the normal select tag abd disable that feature in ios . Check this link to understand better what i mean : http://alvinalexander.com/iphone/iphone-ipad-html-select-widget-wheel .
see the following code hope it will help you...enjoy code
-(void)showPicker{
UIToolbar *toolPicker = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolPicker.barStyle = UIBarStyleDefault;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(hidePicker)];
[toolPicker setItems:[NSArray arrayWithObjects:cancelButton, nil]];
pickerCategory = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
pickerCategory.delegate=self;
pickerCategory.dataSource=self;
pickerCategory.showsSelectionIndicator = YES;
txtCategory.inputView=pickerCategory;
[pickerCategory addSubview:toolPicker];
CGRect thePickerFrame = pickerCategory.frame;
thePickerFrame.origin.y = toolPicker.frame.size.height;
[pickerCategory setFrame:thePickerFrame];
UIView *view = [[UIView alloc] init];
[view addSubview:pickerCategory];
[view addSubview:toolPicker];
UIViewController *vc = [[UIViewController alloc] init];
[vc setView:view];
[vc setContentSizeForViewInPopover:CGSizeMake(320, 260)];
popover = [[UIPopoverController alloc] initWithContentViewController:vc];
[popover presentPopoverFromRect:txtCategory.bounds inView:txtCategory permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)hidePicker{
[popover dismissPopoverAnimated:YES];
}
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.
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];
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];