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];
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];
}
How to show a pop up window when the user clicks on the particular field in my table view.
It should pop a window ant it should display the user contact information.
I do not want to use navigationbar controller here.
Kindly help me
I have written code of UIPopOverController with DatePicker as a example for you. just refer this example and set according your need
-(IBAction)tDriveBtnPressed:(id)sender
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
txtDate.text = [NSString stringWithFormat:#"%#",
[df stringFromDate:[NSDate date]]];
[df release];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(pickerDone:)];
[barItems addObject:doneBtn];
[doneBtn release];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
CGRect pickerRect = datePicker.bounds;
datePicker.bounds = pickerRect;
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);
[datePicker addTarget:self action:#selector(dateChange:) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:pickerToolbar];
[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
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[tDriveBtn frame]
fromView:[tDriveBtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
// popoverRect.size.height = ;
[popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
-(void)dateChange:(id)sender
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
txtDate.text= [NSString stringWithFormat:#"%#",
[df stringFromDate:datePicker.date]];
[df release];
}
- (void)pickerDone:(id)sender
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
txtDate.text= [NSString stringWithFormat:#"%#",
[df stringFromDate:datePicker.date]];
[df release];
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
}
You can display your new viewController using presentModalViewController method. I use it like this way:
- (IBAction)addNewBuidling:(id)sender
{
NewBuilding *new=[[NewBuilding alloc]initWithNibName:#"NewBuilding" bundle:nil];
new.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
new.modalPresentationStyle=UIModalPresentationFormSheet;
[self.navigationController presentModalViewController:new animated:YES];
new.view.superview.frame = CGRectMake(0, 0, 357 ,117);//it's important to do this after. Take a frame size exactly of your new viewController's size.
new.view.superview.center = self.view.center;
[new release];
}
This is how my NewBuilding viewController will appear on screen.
Edit 1:
In this written in presentModalViewController reference: "On iPhone and iPod touch devices, the view of modalViewController is always presented full screen." so for iPhone it may not serve your purpose.
if you want to display less details then you can use following option.
declare below code in .h file
UIWindow *alertWindow;
Write following code in .m file.
alertWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // you must release the window somewhere, when you do not need it anymore
alertWindow.windowLevel = UIWindowLevelAlert; // puts it above the status bar
alertWindow.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
/*CUSTOM VIEW obj*/.center = CGPointMake(alertWindow.frame.size.width/2, alertWindow.frame.size.height/2);
[alertWindow addSubview:/*PUT YOUR CUSTOM VIEW HERE*/];
[alertWindow setHidden:NO];
this code is display you custom view like UIAlertView.
you put above code in UITableView Delegate method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}
For hide window
[alertWindow setHidden:YES];
[alertWindow release]; alertWindow = nil;
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];
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.