Implement iOS select menu - ios

I would like to implement a select menu like that (when an user clicks on a button it should appear):
How is that menu called and how can I implement it with a storyboard?
Thank you!

That is called a UIActionSheet
You need to add it programatically, not by storyboard, this is an example of adding a new one:
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:#"Title"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Delete"
otherButtonTitles:#"Option 1", #"Option 2", nil];
[actionSheet showInView:self.view];
You can find all the documentation here:
UIActionSheet Class Reference

You can achieve this by using UIActionSheet, and by the way it looks like in iOS7 and here are good tutorials how to create it:
http://littlereddoor.co.uk/welcome/blog/beginning-ios-development-create-and-show-an-instance-of-uiactionsheet/
http://mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate/
http://iphone.milktin.com/2013/06/working-with-uiactionsheet.html

Related

Getting warning for UIPopoverBackgroundVisualEffectView

I'm presenting a UIActionSheet in my view and one of the action sheet's buttons presents another action sheet. When I present the second action sheet on iPad I get this warning message in the logs:
UIPopoverBackgroundVisualEffectView is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
This is my code:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Option"] delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Sort", nil];
actionSheet.tag = 1;
[actionSheet showInView:self.view];
And in the delegate:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[self showSortAction];
}
-(void)showSortAction {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Sort By" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"A-Z", #"Z-A", #"Newer to older", #"Older to newer", nil];
actionSheet.tag = 2;
[actionSheet showInView:self.view];
}
My guess is that the presentation of the second action sheet is causing the first action sheet's opacity to change, triggering the warning you're seeing. Instead of calling -showSortAction from within -actionSheet:clickedButtonAtIndex:, call it from within -actionSheet:didDismissWithButtonIndex:. This gives the first action sheet enough time to disappear from the screen before the second one starts animating in. (See the UIActionSheetDelegate documentation – specifically, the detail text for the clicked and did-dismiss methods.)
While we're on the subject, though, note that the UIActionSheet documentation says it's deprecated as of iOS 8. Unless you're programming against iOS 7 or older, consider transitioning to UIAlertController as soon as possible.
#Tim is correct above.
You shouldn't be using the deprecated UIActionSheet anymore. His solution about using actionSheet:didDismissWithButtonIndex: might have worked before but as per https://stackoverflow.com/a/25044710/1634905 it won't work anymore as Apple has moved on to UIAlertController.
You really should switch your code to UIAlertController instead of the old method to fix the issue.

ActionSheet with one button issue with ios 8

In my application i found that actionsheet is not displaying properly, so i create fresh demo project with single view and one button on button action i have write code like
-(IBAction)testActionsheet:(id)sender{
UIActionSheet *objAction=[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"ActionSheet issue",nil];
[objAction showFromRect:CGRectMake(300, 500, 90, 9) inView:self.view
animated:YES];
}
but is show some cut from top side... do any one have solution for this, with actionsheet?
UIActionSheet is deprecated in iOS 8.
please check this link
UIActionSheet is deprecated in iOS 8
you can use UIAlertController instead of actionsheet
UIAlertController

Add Actionsheet in UITabbarcontroller in iOS

I created UITabbar in UIViewController. Then i added a UIActionSheet to it but when the actionsheet appeared, when top part of button "Cancel" is clicked, it works, but when I click the bottom part of "Cancel", there's no response. I used this code to add the actionsheet:
actionSheetDelete = [[UIActionSheet alloc] initWithTitle:#"Do you want to continue?" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Delete Item(s)" otherButtonTitles:nil];
actionSheetDelete.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheetDelete showInView:self.view];
[actionSheetDelete release];
When i click on action sheet, i always show this alarm in console:
Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].
Do you have any suggestion? Thanks in advance
Try:
[actionSheetDelete showFromTabBar:self.tabBarController.tabBar];
You could show it in the view of the UITabBarController:
actionSheetDelete = [[UIActionSheet alloc] initWithTitle:#"Do you want to continue?" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Delete Item(s)" otherButtonTitles:nil];
actionSheetDelete.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheetDelete showInView:self.tabBarController.view];
[actionSheetDelete release];
Alternatively, a slightly more robust version might be:
[actionSheetDelete showInView:[UIApplication sharedApplication].keyWindow];
You are trying to show the action sheet from the view itself. This cannot be done considering you have the UITabBarController inside the view already. Therefore, you have to set it from the tab bar when it is shown. This will ensure that the buttons are not loaded underneath the view of the tab bar, and allow the availability of all the actions associated with the tab bar.
Therefore, you should use
[actionSheetDelete showFromTabBar:];
so that the tab bar is the initial location of where the action sheet is shown
Hope this helps!

Showing a UIActionSheet from a UIBarButtonItem trouble

So I set up my storyboard files and whatnot and made an action for my UIBarButton. In this method I create an action sheet and display it. But it seems no matter what I do it always displays from the bottom. Can't you get it to pop down from the navbar with a little arrow in the border that points to the button you clicked? Well, I'm having trouble finding the right method. Here's what I have tried:
- (IBAction)actionBtnPressed:(UIBarButtonItem *)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Options" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Report User" otherButtonTitles: nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showFromBarButtonItem:sender animated:YES];
}
I have also tried
[actionSheet showFromToolbar:self.navigationController.toolbar];
instead of showFromBarButtonItem, but these methods aren't reading my mind that I want it to display from the button. Any ideas?
For an iPhone, actionsheet is always displayed from bottom of the screen. What you meant is a UIPopover which is available only for an iPad. However, you can use a custom popover if you want to use the same feature in your app. Check WEPopover. It allows you to create pop over in iPhone and it can be safely used to draw popover in your app. You can show the required items inside this popover.

Disabling ActionSheet dismiss on ipad when user touches outside popover

I have an actionsheet showing in my app and it all work fine on the iphone. However, on ipad it automatically creates the actionsheet within a popover and I can't get it to disable the dimissing whe the user touches outside the actionsheet.
I have changed how the actionsheet is displayed for the ipad and is now shown using:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Choose a preloaded picture", #"Use a photo", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
actionSheet.tag = 1;
[actionSheet showFromRect:CGRectMake(100, 0, 300, 300) inView:self.view animated:YES];
[actionSheet release];
I have also tried using.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Any idea on how I can stop the uiactionsheet popover from dismissing when a user touches outside the actionsheet?
Your popoverControllerShouldDismissPopover: method won't be called because it's a UIPopoverControllerDelegate method, and you're dealing with a UIActionSheet. Since the UIKit automatically creates the popover controller for you, you won't get a chance to set its delegate. You could access the popover view itself with [popoverActionsheet superview], but that won't give you the UIPopoverController.
From a user experience standpoint, Apple would ask you not to implement such behavior— if you need to present options in a modal fashion (where they don't go away until the user makes a choice) then the user will be more familiar with a UIAlertView, or a modally-presented view controller of your own.

Resources