UIDatePicker Cancel Overlaps - ios

The CANCEL area is over the top of the date, the picker still works but is hidden under the cancel button.
This code used to work so I am guessing its something with the newer OS?
I haven't needed to mess with the iPhone code for a while and now find a problem with a date picker. So I am not up to speed at all on XCode but trying to muddle through to see what the problem is. I guess I will eventually get up to speed again and figure out what is wrong, but if anyone can tell me what it is that would be awesome.
-(void)willPresentActionSheet:(UIActionSheet *)actionSheet {
switch ([actionSheet tag] ) {
case 1://date
{
NSDate *d;
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 50, 100, 116)];
[pickerView setTag:100+[actionSheet tag]];
[pickerView setDatePickerMode:UIDatePickerModeDate];
[actionSheet addSubview:pickerView];
[pickerView release];
NSArray *subViews = [actionSheet subviews];
[[subViews objectAtIndex: SelectButtonIndex] setFrame:CGRectMake(20, 266, 280, 46)];
[[subViews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 317, 280, 46)];
}
break;
}
}
- (IBAction)btnDate:(id)sender {
UIActionSheet *asheet = [[UIActionSheet alloc]
initWithTitle:#"Pick the date"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Select"
, nil];
[asheet setTag:1];
[asheet showInView:[self.view superview]];
[asheet setFrame:CGRectMake ( 0, 117, 320, 383)];
[asheet release];
}

Related

iPhone - AlertView text field shifts using iOS6 [duplicate]

This question already has answers here:
UIAlertView with textfield and three buttons issue in ios 6
(4 answers)
Closed 9 years ago.
I have a problem with my UIAlertView text field using iOS6.
The text field shifts all the way to the top. When i use iOS7, the text field is in the right spot.
Can someone help me? Here is the code:
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Item?"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Add another", #"Done",nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeWords;
[message show];
The text field appears on the title text (here: Item?)
did you try this :
-(void)willPresentAlertView:(UIAlertView *)alertView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
{
[alertView setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alertView subviews];
UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
[message setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
[cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
[savebutton setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
[saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
[textfield setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
Actually this can be fixed manually by detecting the system version. Here is the right way to do this in this post
Try this code, it will work.
- (IBAction)showAlert:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title = #"Item?";
alertView.message = nil;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView addButtonWithTitle:#"Cancel"];
[alertView addButtonWithTitle:#"Add another"];
[alertView addButtonWithTitle:#"Done"];
[alertView show];
}

iOS7 and UIActionSheet with Time Picker

I had an iOS6 app that used the following code to create a UIActionSheet with a Time Picker:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
//Configure picker...
[pickerView setMinuteInterval:5];
[pickerView setTag: 4];
[pickerView setDatePickerMode:UIDatePickerModeTime];
//Add picker to action sheet
[actionSheet addSubview:pickerView];
//Gets an array of all of the subviews of our actionSheet
NSArray *subviews = [actionSheet subviews];
[[subviews objectAtIndex:1] setFrame:CGRectMake(20, 266, 280, 46)];
[[subviews objectAtIndex:2] setFrame:CGRectMake(20, 317, 280, 46)];
}
It worked like a charm until I tried it in iOS7, it always crashes when I click the input field that pops up the action sheet. Here is the code behind the input field:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
selectedTag = textField.tag;
// the input field that needs to show the actionsheet has tag 1.
if (selectedTag == 1) {
UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:#"Select a time:"
delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil
otherButtonTitles:#"Select", nil];
[asheet showInView:[self.view superview]];
[asheet setFrame:CGRectMake(0, 110, 320, 500)];
textField.userInteractionEnabled = NO;
}
textField.userInteractionEnabled = YES;
}
When the app craches, I get the following message:
If you want a datepicker to be presented while clicking the textfield, you can directly present the datepicker. Make the datepicker as your textfield's inputview.
pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
//Configure picker...
[pickerView setMinuteInterval:5];
[pickerView setDatePickerMode:UIDatePickerModeTime];
[dateTextField setInputView:pickerView];
Try this..
[asheet showInView:self.view];

how to manage uipickerview in uiactionsheet

i am trying to show the UIPickerView in UIActionSheet . from the below mentioned code it works great in portrait mode but looks wired in Landscape Mode. (my app support iPhone 4/5 n landscape orientation also).
what i am doing wrong ?
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame=CGRectMake(0, 40, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"OK"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
Finally i got the solution
First of all i have to set the width of the picker view as i have mentioned
CGRect pickerFrame=CGRectMake(0, 40, 0, 0);
so it can be like
CGRect pickerFrame=CGRectMake(0, 40, 320, 0);
I found one more good solution :
Just call the picker view in action sheet by clicking a text field:
self.textField.inputView = yourCustomView;

UIdate picker does not move freely

I have a UIbutton on my UIViewController. Clicking that opens up an UIActionSheet with a UIDatePicker on it and a close button. I set the UIDatePicker to date mode .So it shows up with todays date. Suppose i want to select 2015 instead of 2013, i have to scroll down. But it won't allow me to scroll down. I have to scroll up once to 2012 and then scroll down. This seems like a minor issue but the client wants to scroll properly down. I checked on my personal phone to set alarm, i can freely scroll down. I don't have to scroll up and then scroll down. So this is what happens on button click.
- (IBAction)btnShowDateNeededClick:(UIButton *)sender
{
UIDatePicker *datePickerView = [[UIDatePicker alloc]init];
datePickerView.datePickerMode = UIDatePickerModeTime;
self.actSheet = [[ UIActionSheet alloc]init];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Close"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blueColor];
closeButton.tag = 101;
[closeButton addTarget:self action:#selector(dismissActionSheetWithTime:) forControlEvents:UIControlEventValueChanged];
[self.actSheet addSubview:closeButton];
[self.actSheet showInView:self.view];
[self.actSheet addSubview:datePickerView];
[self.actSheet sendSubviewToBack:datePickerView];
[self.actSheet setBounds:CGRectMake(0, 0, 320, 500)];
}
As you see, i have datePicker, segment control as a button added to UIActionsheet. Now do i have to change settings or date picker? If you need more information, please ask. Thanks.
Try This. may be this help.
In .h File.
UIDatePicker *datePickerView;
UIActionSheet *Actionsheet1;
In .m File
In viewDidLoad Method
// Picker Initialization
datePickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
datePickerView.datePickerMode = UIDatePickerModeDateAndTime;
Make a function which will be called on your Button click
-(void) Create_Start_Date_Picker_Function
{
Actionsheet1 = [[UIActionSheet alloc] initWithTitle:nil delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
Actionsheet1.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[Actionsheet1 addSubview: datePickerView];
[Actionsheet1 showInView:self.view];
[Actionsheet1 setBounds:CGRectMake(0, 0, 320, 485)];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blueColor];
[closeButton addTarget:self action:#selector(Dismiss_Actionshit1) forControlEvents:UIControlEventValueChanged];
[Actionsheet1 addSubview:closeButton];
}
And in method for dismiss actionshit.
-(void) Dismiss_Actionshit1
{
// Your action sheet dismiss code
}

UIPicker / UIActionSheet works fine on iPhone but only thin line on iPad

The following Code works fine on iPhone, but not on iPad. Only get a thin line instead of the full view. Have been researching and maybe something with the rect for the picker? All size numbers seem to be reasonable.
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil
cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
if ( isipad ) pickerFrame = CGRectMake(0, 345, 400, 216);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[pickerView release];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Select"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(10, 7.0f, 100.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[closeButton release];
UISegmentedControl *skipButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Skip Birth Year"]];
skipButton.momentary = YES;
skipButton.frame = CGRectMake(200, 7.0f, 100.0f, 30.0f);
skipButton.segmentedControlStyle = UISegmentedControlStyleBar;
skipButton.tintColor = [UIColor blackColor];
[skipButton addTarget:self action:#selector(skipActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:skipButton];
[skipButton release];
[actionSheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
Well, got it to work by putting most of the code in
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
including
pickerFrame = CGRectMake(0, 0, 320, 214);
AND
initWithTitle:#"\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
for the action sheet. Magic I guess.
Is this correct:
CGRect pickerFrame = CGRectMake(0, 40, 0, 0); //This line sets the frame height and width equal to 0.
if ( isipad ) pickerFrame = CGRectMake(0, 345, 400, 216);
Is your isipad bool working ok?
Thanks for your post ort11.
I needed to make an iPad app and I did working copy-paste code from iPhone app and on iPad is the same: a small line :)
My needs is a language chooser only, nothing else.
Here are the codes based on your answer:
- (IBAction)btLanguageChooserPressed {
NSLog(#"btLanguageChooserPressed");
[self createLanguageSheet];
// show the sheet: will be invoked the willPresentActionSheet method
[sheet showInView:self.view];
}
- (void)createLanguageSheet {
NSLog(#"createLanguageSheet()");
// hoolly crap, need to initialize the title with: #"\n\n\n\n\n\n\n\n\n\n\n\n\n\n" to get working!!!
sheet = [[UIActionSheet alloc] initWithTitle:#"\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[sheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
}
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
CGRect pickerFrame = CGRectMake(0, 0, 320, 216);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[sheet addSubview:pickerView];
// add close button:
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"OK"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(120, 12, 100, 30);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(dismissSheet:) forControlEvents:UIControlEventValueChanged];
[sheet addSubview:closeButton];
[sheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
//[sheet showInView:self.view];//already called, why need again?
//[sheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
}
at runtime I do a cache in a variable:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(#"Selected: %#", [arrayLanguages objectAtIndex:row]) ;
selectedRow = row;
}
and here is the finish:
- (void)dismissSheet:(id)sender {
[sheet dismissWithClickedButtonIndex:0 animated:YES];
NSString* selectedLanguage = [arrayLanguages objectAtIndex:selectedRow];
NSLog(#"dismissSheet() selectedLanguage: %#",selectedLanguage);
switch (selectedRow) {
case 0://English
imgCurrentLanguage.image = [UIImage imageNamed:#"english.png"];
break;
case 1:// Deutsch
break;
case 2://Français
break;
case 3://Italiano
break;
case 4://Español
break;
default:
break;
}
// TODO: do the changes in GUI
}
I am not able to move this actionsheet from the center of the screen to botton- left corner. But I am trying...
I think this would be the cleanest solution :
#interface MyActionSheet : UIActionSheet
#property (nonatomic, strong) IBOutlet UIView * customView;
#end
#implementation MyActionSheet
-(CGRect)bounds {
return self.customView.bounds;
}
#end
then:
MyActionSheet * s = [[MyActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
s.customView = _auxView;
[s addSubview:_auxView];

Resources