UIPickerView not scrolling in actionSheet - ios

I've added an UIPickerView into a UIActionSheet. Everything ok, but my picker can't be scrolled to choose a value. Any suggestions?
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
UIPickerView * picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 270)];
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
[actionSheet addSubview:picker];
[picker release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 500)];
[actionSheet release];
Best regards,
Dorin

An alternative solution to what you're trying to achieve is to set text field's inputView and inputAccessoryView. Setting these will replace the standard keyboard and bring in custom views. This includes the picker view. I happened to write a short example in this question here. Take a look and see if it helps.

Related

checkbox in uialertview in ios8

I want to add checkbox exactly as the below image
below is my code:
UIButton *nameField = [[UIButton alloc] initWithFrame:CGRectMake(120, 0, 30, 30.0)];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
[v setBackgroundColor:[UIColor clearColor]];
[nameField setImage:[UIImage imageNamed:#"unchecked.png"] forState:UIControlStateNormal];
[v addSubview:nameField];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Delete selected pods from server?" message:
#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[av setValue:v forKey:#"accessoryView"];
av.message = #"This will delete all the posts related to the pictures you want to delete!";
[av show];
with the above code I am getting as :
I want to get checkbox beside message..
Any help or suggestion how to proceed?
You can use https://github.com/wimagguc/ios-custom-alertview
Create your custom content view and set it like
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
UIView *customView ..; //Your custom view
[alertView setContainerView:customView];
I would suggest you to do not do that.
accessoryView is not a public exposed API and you risk an app rejection
UIAlertView is deprecated in iOS8, use UIAlertController
You can use a third party library, I usually integrate MRProgress in my projects, you can create your own nib and add it.

Adding UIActivityIndicatorView to UIAlertView

I want to add an activity indicator inside the message , the uiAlert message, i tried basically everything on the internet, and nothing worked for me, i will just have the uialertview alone , here's my code
UIAlertView *waitAlert = [[UIAlertView alloc] initWithTitle:#"Please Wait...." message:#"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
progress.color = [UIColor blackColor];
[waitAlert addSubview: progress];
[progress startAnimating];
[waitAlert show];
This is what i end up having
what am i missing!?
in iOS 7 you cannot addSubview anything on UIAlertView,that was possible till iOS 6.1.so MBProgressHud is the best and simple solution for that
Try to add your UIActivityIndicator using the UIAlertViewDelegate method:
- (void)didPresentAlertView:(UIAlertView *)alertView
{
UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
progress.frame = CGRectMake(125, 50, 30, 30);
[progress startAnimating];
[alertView addSubview:progress];
}

UIDatePicker Cancel Overlaps

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];
}

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;

Resources