In UIActionSheet the cancel button not showing for iphone? - iphone

In my application when I click on change image it's asks UIActionsheet with three actions take photo ,choose from library and cancel.Take photo ,choose from library are showing but cancel didn't showing where is the problem.
this is my code
- (void)viewDidLoad
{
[super viewDidLoad];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..."
delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Take Photo", #"Choose from library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}

Its because...I think you are using the default view size -Retina 4 full screen as your view size...Just try and change your view size to Retina 3.5 full screen from the Attributes inspector...!!!

You may want to take a look at the alternative methods for presenting an action sheet in the class reference. However, you may want to try using one of the following (if you have a toolbar)
– showFromBarButtonItem:animated:
– showFromToolbar:
Additionally, using the following
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
will only ever result in the action sheets style being default.

try this one...
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..."
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Cancel"
otherButtonTitles:#"Take Photo", #"Choose from library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];

Since your problem is not with your code. Maybe you are using the wrong method to display your UIActionSheet.
A UIActionSheet can be displayed with following methods:
– showFromTabBar:
– showFromToolbar:
– showInView:
– showFromBarButtonItem:animated:
– showFromRect:inView:animated:
take a look at Apple's UIActionSheet reference.
Since you use a TabBar, the Cancel button may also be below. I would test that too.

Please refer this link.
And you can refer below code also, it may help you:
(void)viewDidLoad
{
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..." delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Take Photo", #"Choose from library", nil];
[actionSheet showInView:self.view];
}

Related

UIActionSheet cancel button not dismissing actionsheet

I have an UIActionSheet and I am specifying the cancel button however it does not dismiss when its tapped?
UIActionSheet *actionSheet = [[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Target Complete" otherButtonTitles:nil] autorelease];
[actionSheet showInView:self.view];
According to the documentation I don't need any code and even when I try and implement the didCancel delegate method its never called?
Try this
[actionSheet showInView:[self.view window]];
UIActionSheet cancel button strange behaviour
This Will do the trick
[actionSheet showInView:[self.view window]];
instead of
[actionSheet showInView:self.view];
use
[actionSheet showFromTabBar:[[self tabBarController] tabBar]];
instead of
[actionSheet showInView:self.view];
this is working fine.. :-)
You need to display from a taskbar or a toolbar on iPhone as it clips some of the controls if you use display in view.
write simplite code
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
this work fine
I found the answer here.
https://stackoverflow.com/a/1530259/1803218
[menu sendSubviewToBack:pickerView];

iPhone, I want to create a popup menu from my tab bar, but what are they call, like copy / paste?

I'd like to create a popup menu, from my tab bar.
I've seen them, but I'm not sure what they called ?
Kind of like a speak bubble.
I think copy / paste is the sort of thing I mean.
You are searching for the UIMenuController.
This question might help you.
That could be the UIActionSheet. You might want to give it a try.
//Your delegate for pressed buttons.
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Your Action for pressed button.
[actionSheet release];
}
//Declare a method to show your sheet
-(void)showActionSheet
{
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle: #"Action Sheet Title"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Delete"
otherButtonTitles:#"Other Button1", #"Other Button2", nil];
[menu showInView:self.view];
}
But you said "bubble", so that could also be the UIAlertView.
Try this:
-(void)showAlertView
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert!"
message:#"This is the message that pops up in the bubble."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
On the iPad, you'd want UIPopoverController, but I think that on the iPhone the same sort of interactions are meant to be performed by a separate, full screen controller or by a UIActionSheet. There's no speech bubble on the iPhone such that I'm aware.

How to make UIBarButtonItem give menu-options?

You know how if you click and hold on a link in Safari (for iPhone obviously) it gives you a list of options like "open in new window", "Open". "Copy" etc?
How do you call this and is it possible to get a UIBarButtonItem to do this (but every time it is clicked not just when held down)?
This is how you show this menu:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel",
destructiveButtonTitle:nil
otherButtonTitles:#"Button 1", #"Button 2", #"Button 3", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:[self view]];
[actionSheet release];
In order to connect it to UIBarButtonItem just point the bar button item to a selector that will include the code above.
Don't forget to implement - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex method of UIActionSheetDelegate.

How do you create a multi button confirmation on the iPhone?

On the iPhone, in the Calendar App when you press the "Delete Event" button a confirmation slides in from the bottom. Does anyone know of any example code for this, or is it just a short view presented modally with a custom background?
If this is made using a custom view, do you know where I can get a background graphic the same as the one used in the Calendar App?
Thanks in advance!
NB: I am not talking about a UIAlertView dialog box, but the slide-in confirmation with multiple buttons.
UIActionSheet is what you are looking for.
Here is some code example to get you started with:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Save photo?" delegate:self cancelButtonTitle:#"No" destructiveButtonTitle:#"Yes" otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
This will slide in an action sheet from the bottom. It has 2 buttons. Yes and No.
When a user selects any button the actionSheet:didDismissWithButtonIndex: method gets called
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
//your code here
}
Your controller class will have to subscribe to the < UIActionSheetDelegate > protocol
Hope this helps!
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"title" delegate:self cancelButtonTitle:#"cancel" destructiveButtonTitle:#"destructive" otherButtonTitles:#"other", nil];
[actionSheet showInView:self.view];
[actionSheet release];

Fill an actionsheet with an array

I have an actionsheet popup in my iphone application. I would like to fill it with strings from an array instead of predetermined values.
I can't find anything online to do this! Perhaps actionsheet isn't the right thing to use?
Right now this is what I'm using to build it:
roomspopup = [ [ UIActionSheet alloc ]
initWithTitle: alertname
delegate: self
cancelButtonTitle: #"Cancel"
destructiveButtonTitle: nil
otherButtonTitles: #"Kitchen", "Dining Room", nil ];
But, instead of "Kitchen" and "Dining Room" I'd like it to fill in from an array. The size of the array (i.e. the number of rooms) is not a fixed number.
#JimTrell
The way to fix that would be to init the UIActionSheet without the cancel button and add this cancel button after you added your other buttons.
First init the sheet with a bunch of nil's:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Choose"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
Then loop through your array with addButtonWithTitle: and finally add the cancel button and set its index:
[actionSheet addButtonWithTitle:#"Cancel"];
[actionSheet setCancelButtonIndex:[yourArray count]];
You can't do it in one line. You'll have to call initWithTitle with an empty set of buttons, and then add your other buttons with loop using addButtonWithTitle:.
I can set up the cancel button at bottom by using this code:
anActionSheet = [[UIActionSheet alloc] initWithTitle:#"Change A/C" delegate:self
cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
for (int i = 0; i < [arraylist count]; i++)
[anActionSheet addButtonWithTitle:[arraylist objectAtIndex:i]];
anActionSheet.cancelButtonIndex = [arraylist count];
[anActionSheet addButtonWithTitle:#"Cancel"];