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];
}
Related
I have tried to add a UIBarButtonItem to my UINavigation bar but I can't get it to show up:
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width,self.view.frame.size.height)];
[self.view addSubview:self.webView];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(#"Back", #"")
style:UIBarButtonItemStyleDone
target:self
action:#selector(remove:)];
[self.navigationItem setLeftBarButtonItem: backButton];
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
self.webView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:self.url];
[self.webView loadRequest:request];
}
- (void)remove:(id)sender
{
[self removeFromParentViewController];
[self.webView stopLoading];
self.webView.delegate = nil;
}
I can't figure out why the button isn't there. Any help would be much appreciated!
Thanks.
Before add UIBarButtonItem to UINavigationBar, First change your UIWebView frame,
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width,self.view.frame.size.height - 50 )];
Here add (-50) to height of UIWebView.
And now, i just write code for how to add UIBarButtonItem to UINavigationBar:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:navBar];
UIBarButtonItem *Button = [[UIBarButtonItem alloc]
initWithTitle:#"MyButton"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(buttonAction)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"This is My Title "];
item.rightBarButtonItem = Button;
item.hidesBackButton = YES;
[navBar pushNavigationItem:item animated:NO];
Here is Method name is buttonActionthat execute/call when you tapped on UIBarButtonItem.
-(void)buttonAction
{
//stuff of code;
}
remove these two lines from your code and check it,
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
or you can add like this,
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"remove"
style:UIBarButtonItemStyleDone
target:self
action:#selector(remove:)];
UINavigationItem *item = [[UINavigationItem alloc]initWithTitle:#"remove"];
[item setLeftBarButtonItem:backButton];
[myBar setItems:[NSArray arrayWithObject:item]];
Richard, I understand what you want to achieve but I am not sure whether you are using a navigation controller already.
Case 1: using UINavigationController
If you are using Navigation Controller already then you don't need to add new Navigation bar.
If you are using NavigationController then show the use the bar from Navigation Controller and your code will work.
below two lines would not be required.
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
Case 2: Not using UINavigationController
If you are not using UINavigationController then you are required to add a Bar and add Bar button in the navigation item of Bar.
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"remove"
style:UIBarButtonItemStyleDone
target:self
action:#selector(remove:)];
UINavigationItem *item = [[UINavigationItem alloc]initWithTitle:#"remove"];
[item setLeftBarButtonItem:backButton];
[myBar setItems:[NSArray arrayWithObject:item]];
and you need to remove following line
[self.navigationItem setLeftBarButtonItem:backButton];
It will work perfectly. Let me know if you find any issues.
I have a UIButton that when clicked, displays a UIPopover with a UIDatePicker in it.
It is supposed to display under button for date of birth, but it is covering it instead.
This is the code I have:
- (IBAction)dateOfBirthButtonPressed:(id)sender{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor blackColor];
UIDatePicker *datePickerTemp = [[UIDatePicker alloc]init];
datePickerTemp.frame=CGRectMake(0,44,320, 216);
datePickerTemp.datePickerMode = UIDatePickerModeDate;
datePickerTemp.maximumDate = [NSDate date];
self.datePicker = datePickerTemp;
[popoverView addSubview:self.datePicker];
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame=CGRectMake(0,0 ,320, 40);
toolbar.barStyle = UIBarStyleBlackOpaque;
NSMutableArray *toolbarItems = [NSMutableArray array];
UIBarButtonItem *cancelButton1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(datePickerCancelButtonClicked)];
UIBarButtonItem *doneButton1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(datePickerSaveButtonClicked)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolbarItems addObject:cancelButton1];
[toolbarItems addObject:space];
[toolbarItems addObject:doneButton1];
toolbar.items = toolbarItems;
[popoverView addSubview:toolbar];
[cancelButton1 release];
[space release];
[toolbar release];
popoverContent.view = popoverView;
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
self.datePopoverController = popoverController;
[popoverContent release];
[popoverView release];
[self.datePopoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[self.datePopoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
NSLog for frame:
DOB button: {{160, 129}, {329, 37}}
Last name label: {{160, 77}, {329, 31}}
Is your button a subview of your view, or buried within another subview? If it is not a direct subview of your view then your coordinate space is off. Try changing your code to:
CGRect buttonRect = [self.dateOfBirthButton convertRect:self.dateOfBirthButton.frame toView:self.view];
[self.datePopoverController presentPopoverFromRect:buttonRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You can try either one of these to see that fix the problem. The second one fix my problem that is similar to yours.
[self.datePopoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.dateOfBirthButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
or
[self.datePopoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.dateOfBirthButton.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I'm using the following code to display a UIDatePicker within a UIPopover that is displayed when a user clicks a UIButton.
The problem is, it is being displayed in an awkward position and I want to add a UIToolBar above the datePicker where there is extra space. This will have cancel and done button. How can I accomplish this? The button that it is displayed from is the Date of Birth one.
- (IBAction)dateOfBirthButtonPressed:(id)sender{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor blackColor];
UIDatePicker *datePicker=[[UIDatePicker alloc]init];
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
[datePicker setMinuteInterval:5];
[datePicker setTag:10];
// [datePicker addTarget:self action:#selector(dateChanged) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverContent release];
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Is there a reason you couldn't just use a UIToolbar?
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 44.0)];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCancel
target: self
action: #selector(cancel)];
UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace
target: nil
action: nil];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone
target: self
action: #selector(done)];
NSMutableArray* toolbarItems = [NSMutableArray array];
[toolbarItems addObject:cancelButton];
[toolbarItems addObject:space];
[toolbarItems addObject:doneButton];
[cancelButton release];
[doneButton release];
[space release];
toolbar.items = toolbarItems;
Then just add the toolbar to your view. Make sure to size it correctly and implement the done and cancel selectors.
[popoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Use sender in place of self.view
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
How to add button to UIPopoverController ?
I am attaching a picture for able to understand very clear.
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor blackColor];
UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,400 ,44)];
toolbar.barStyle =UIBarStyleBlackTranslucent;
NSMutableArray *ButtonArray=[[NSMutableArray alloc ]init];
Save=[[UIBarButtonItem alloc ]initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(save_pressed)];
UIBarButtonItem *space=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *cancel=[[UIBarButtonItem alloc ]initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancel_pressed)];
[ButtonArray addObject:cancel];
[cancel release];
[ButtonArray addObject:space];
[space release];
[ButtonArray addObject:Save];
[Save release];
[toolbar setItems:ButtonArray];
[ButtonArray release];
[popoverView addSubview:toolbar];
[toolbar release];
picker = [[UIPickerView alloc] init];
picker.frame = CGRectMake(0, 44, 400, 340);
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
[popoverView addSubview:picker];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController setPopoverContentSize:CGSizeMake(400, 264) animated:NO];
[popoverController presentPopoverFromRect:btn.frame inView:scr_AddLocation permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[popoverView release];
[popoverContent release];
here I m adding Picker To Popover When We Pressed Button .
The cancel button (if that is what you are referring to) is the rightBarButtonItem of the UINavigationController's navigation bar. You can set it to be a standard UIBarButtonItem (as is done here) or a custom one (whose view you can create).
I have added a new file to my project in that i am creating the screens programatically and i used following code to create a grouped table view with a title bar & 2 buttons on title bar, but its creating only grouped table but not title bar y it is so, can any one help me thanx in advance
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Add Item";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(cancel_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:#selector(save_Clicked:)] autorelease];
self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 415)style:UITableViewStyleGrouped];
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithTitle:#"+"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(Add)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
[journeylist.tabBarItem initWithTitle:#"Journey List" image:[UIImage imageNamed:#"listIcon-H.png"] tag:1];
journeylist.navigationItem.title =#"Journey List";
NSArray *controllers = [NSArray arrayWithObjects:journeylist,appstore,settings,about,nil];
self.viewControllers = controllers;
Try this.
Your table frame is CGRectMake(0, 0, 320, 415) so top left, you'll need to leave room for the title bar say CGRectMake(0, 40, 320, 415).
I think you have to present it like this.
SomeViewController *controller = [[SomeViewController alloc]
initWithNibName:#"SomeViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:controller];
navController.navigationBar.tintColor = [UIColor grayColor];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[controller release];
Edit
When you are showing that controller with table view you have to frist add it to a navigation controller in order to show the navigation bar.