Placing textfield in Actionsheet - iphone

Is it possible to place a text field in Actionsheet? I try this code:
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil];
UITextField *pickerView_freq_payment = [[UITextField alloc] init];
[menu addSubview:pickerView_freq_payment];
[menu showInView:self.view];
[menu sendSubviewToBack:pickerView_freq_payment];
[menu setBounds:CGRectMake(0,0,320, 300)];
CGRect pickerRect = pickerView_freq_payment.bounds;
pickerView_freq_payment.bounds = pickerRect;
[pickerView_freq_payment release];
[menu release];
but it doesn't show any text field. I found information on displaying buttons in Actionsheet, but I need to place text fields instead of buttons.
How can I do this? Can anyone please help me?

Dont need to do this,
You need to implement alert with textfields for change password purpose check this link

I would strongly recommend against this. UIActionSheet has a very specific purpose on the iPhone, and adding text fields to it probably goes against Apple's Human Interface Guidelines.
Could you tell us why you need a text field? This way, we could suggest a more appropriate construct, like a modal view controller.

Related

ios UIActionSheet cancel button doesn't work right

I have this problem:
here is my code:
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:#"Share the race" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Send with mail" otherButtonTitles:nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
and everything seems ok, the 2 buttons are showed right, the "send with mail" button is ok, but the cancel catch the click only on the upper side...
here a shot that illustrate the situation:
how can I solve this?
thanks:)
My guess is that the bottom portion of the UIActionSheet extends beyond the bounds of the view, and so doesn't respond to touches.
To test this theory, add another button and see if all upper buttons work fine but the bottom button still exhibits this behavior.
To fix this problem, make sure the view extends to the bottom of the screen. If you have a tabBar in your app, that's going to be my suspect for the problem. You could use showFromTabBar: if you want the sheet above the tabBar, or showFromToolbar: to show it from a toolBar.
If you don't have a bottom bar, then I'm wrong and have no idea.
You should show the action sheet as a subview of the application window, not of the current view.
UIActionSheet *actionSheet = [[UIActionSheet alloc] init...];
// ...
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
May be it will help others.
Happy Coding :)
use
[actionSheet showFromTabBar:[[self tabBarController] tabBar]];
instead of
[actionSheet showInView:self.view];

Action Sheet warning?

I have added an action sheet in my app. My application is tab bar based app.
I have added this in this way
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Take photo",#"Use existing photo",nil];
actionSheet.actionSheetStyle = UIBarStyleBlackTranslucent;
[actionSheet showFromTabBar:self.view];
But it shows warning:
How can I remove it. As the same time I am in the tab in which I want to display the action sheet.
[actionSheet showFromTabBar:self.tabBarController.tabBar];
Try this ,it might help you.
If you are in the tab, shouldn't it be [actionSheet showFromTabBar:self.tabBarController.tabBar];?
If you are use tabbar controller then use like this
[actionSheet showFromTabBar:(UITabBar *)[appDelegate.tabBarController view]];

How to display custom view in UIActionSheet?

I have a UIView with a date picker that I'd like to display in an action sheet. I'm using the following code:
-(IBAction) button_click:(id)sender{
//UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:#"the title" delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Destructive" otherButtonTitles:#"other", nil];
UIActionSheet *sheet = [[UIActionSheet alloc] init];
ActionSheetController *actionSheet = [[ActionSheetController alloc] initWithNibName:#"ActionSheetView" bundle:nil];
[sheet addSubview:actionSheet.view];
[sheet showInView:self.view];
}
What I get is a little bit of the top part of the new view coming up from the bottom and that's it. If I comment the two middle lines of code and uncomment the top part to display a regular action sheet, it works fine. Any ideas what I might be doing wrong?
use UIActionSheetDelegate and after that you can with this delegate add for example a image to button of alertsheet
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet{
UIImageView *sample = [[UIImageView alloc] initWithImage:[UIImage
imageNamed:#"Someimage.png"]];
[actionSheet addSubView:sample];
}
I do not believe you can specify Custom Views in a UIActionSheet. My understanding is that you can only display a title and 1 or more buttons. Below is the description of UIActionSheet in the Apple documentation:
Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.
UIActionSheet Class Reference
I've discovered the behavoir occurs because I haven't used the UIActionSheet constructor properly. The buttons and title should be included:
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:#"Date Picker" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
You might want to check out an UIActionSheet alternative I made which lets you display custom content views without any dirty hacks: https://github.com/JonasGessner/JGActionSheet It has some other advantages over UIActionSheet as well!

create share menu and add images

I've two questions for you, which i can't solve:
1) How do I create a menu like this -->
(source: momolog.com)
.
2) How can I add multiple images like the iApp named HotBook do?
.
Thanks in advance for your help.
Sean
Old post, but this may help others who come across the page...
For #1, that's a UIActionSheet. You can instantiate it with this:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Share" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"On Facebook", #"On Twitter", nil];
[actionSheet showInView:self.view];
[actionSheet release];
Note that your UIViewController must conform to the UIActionSheetDelegate protocol.

Strange Problem with UIDatePicker in ActionSheet - Below that Selection indicator I can't select anything, It's become like disabled

I am implementing datepicker with Action Sheet with the following code :
-(void)popupActionSheetWithDatePicker
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Done",nil];
UIDatePicker *picker = [[UIDatePicker alloc] init];
self.datePicker = picker;
[self.datePicker setDatePickerMode:UIDatePickerModeDate];
[sheet addSubview:self.datePicker];
[sheet showInView:self.view];
[sheet setBounds:CGRectMake(0,0, 320,500)];
CGRect pickerRect = self.datePicker.bounds;
pickerRect.origin.y = -80;
self.datePicker.bounds = pickerRect;
[sheet bringSubviewToFront:self.datePicker];
[picker release];
[sheet release]; }
Now, The Picker pops up & working perfactly Except below the Selection Indicator.
I mean On & Above the Selection indicator I am able to choose date, month & year, but Below that Selection indicator I can't select anything, It's become like disabled.
Can't find the reason or solution.
If Possible Please send any working Datepicker with UIActionsheet code.
Thanks in advance.
I have had a very similar issue with parts of a view not working when used with a UIActionSheet. My problem was that the bounds of the UIActionSheet were larger than the view I had added it to.
My solutions was to change where i inserted the sheet
[sheet showInView:self.view];
You may need to add it higher up for example
[sheet showInView:self.view.superview];
Hope this at least sets you on the right track
I had this problem also , i supose you have an UIToolbar behind the picker. Just do
[self.navigationController setToolbarHidden:YES];
while in picker , then
[self.navigationController setToolbarHidden:NO];
hope this help