UIActionSheet cancelButtonTitle ipad - ipad

I'm using UIActionSheet to present a set of choices to the user. It works fine on iPhone and iPod Touch, but on the iPad the "cancel" option is always hidden. That is, the "dialog box" with the options appears, but the "cancel" button is missing.
Here's the code:
self.popupQuery = [[[UIActionSheet alloc] initWithTitle:title
delegate:self
cancelButtonTitle:cancelButtonTitle
destructiveButtonTitle:nil
otherButtonTitles:option0, option1, cancelButtonTitle, nil] autorelease];
The UIActionSheet docs state:
cancelButtonTitle:
The title of the cancel button. This button is added to the action sheet automatically and assigned an appropriate index, which is available from the cancelButtonIndex property. This button is displayed in black to indicate that it represents the cancel action. Specify nil if you do not want a cancel button or are presenting the action sheet on an iPad.
I'm not passing nil, so I'm not clear what's going on. Is this a bug?

It might depend on how you are presenting your UIActionSheet, but bear in mind that tapping outside the UIActionSheet is the cancel button on the iPad.
While there may be an alternative way to present the UIActionSheet, the default will leave you with out that cancel button.
EDIT:
According to another answer on a very similar question, you can make the cancel button appear on iOS 4.2 and prior by using the following code. Note that in iOS 4.2.1, this seems to have been changed and will no longer work.
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
or this:
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

Related

Is it safe to present UIAlertController (alert style) on iPad without popover?

In my app, I display a UIAlertController when the user taps on a button on the screen. I either use a UIAlertController or a UIAlertView, depending on the API availability (since my app supports both iOS 7 and 8).
I simply want to display an alert view to the user so I'm using the .Alert style for my UIAlertController.
When the user is on an iPad, is it safe to display the UIAlertController (Alert style) without configuring a popover?
I saw some tutorials online. From my understanding, if using a UIAlertController (Action Sheet style), I need to configure a popover or else the app will crash. I just want to know if it works the same way with an Alert style UIAlertController.
I did some test on my iPad and the app did not crash without the popover. But I want to make sure this is safe.
You never use a UIPopoverController with UIAlertView or UIAlertController (no matter its style).
iOS will internally use a popover on an iPad when the UIAlertController style is "action sheet" but you don't deal with that yourself.
So you have nothing to worry about. Use UIPopoverController as-is using the presentViewController:animated:completed: method no matter the device and you are fine.

Let the UIAccessibilityPostNotification complete in UIAlertView

I want to announce a message through UIAccessibilityPostNotification in a UIAlertView. My problem is that the alert view closes and the message abruptly stops (at least that is my analysis), barely two words get spoken. Is there any way to let the notification complete? My code is as follows:
//Function which calls UIAlertView
-(IBAction)foo:(id)sender
{
UIAlertView* myAlert = [[UIAlertView alloc] initWithTitle:#"Select to get more information"
message:#""
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"a",#"b",#"c", nil];
myAlert.tag=2;
[myAlert show];
//Code comes here immediately, even if I don't select anything on alertView.
NSLog(#"Does it come here? Yes!");
}
My AlertView:
if ([alertView tag]==2)
{
//Some code
NSString* message = #"Long message";
if (UIAccessibilityIsVoiceOverRunning())
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, message);
else
NSLog(#"Voice-over is not running.");
}
I am also ready to change my code logic. I tried if the code continues after we select a choice on alert view, so that I can make the message variable global and post the notification through the foo function. It doesn't happen as expected. Program stops after alertView closes.
Does any workaround exist? I am an amateur iOS programmer so a little code along with the explanation would help.
P.S. I can even use something other than alert view, if there is any. I just want to have a pop-up and some buttons as choices.
IMO, you should create your on Custom popup using UIView to display options to the end user. Then first display your popup that gives user the options, once user selected one of them (or tap a button after selecting one of them), call UIAlertView to show the relevant messages.
Hope this way your problem will be solved.

uialertview glossy look and feel

I have created a uialertview
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Prohibited"
message:#"In-App Purchase is disabled, cannot make a purchase!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[alert show];
Which creates a dialog as below
But I need something like
How do I get this glossy look and feel ? Working in iOS 7.1, xocode 5.
My app uses UIWebView, UIViewController
It will look glossy as seen in that image on iOS 6 and lower OSs. iOS 7 is now flat.
Now if you wish to create your own UIAlertView by subclassing it. Theres a few tutorials that will teach you how to. but you'll need to create your own graphics and will cause a extra programming.
All your custom drawing will have to be inside the drawRect or overriding the various elements in the UIAlertView.
I would look at the way this github project does it's own customization to the UIAlertView
https://github.com/Sumi-Interactive/SIAlertView
For example:
The non glossy UI goes with IOS 7, I have an old app which has IOS 6 as the target version - it has the glossy alert views in an IOS 6 device (iPhone 3GS) but once running in an IOS 7 device it follows the new format., If it is really important you may want to simulate UIAlertviews using modal subviews .... [self presentViewController: mediaUI animated: YES completion:NULL]; or pop view controllers if coding for iPad.
Here is an old sample code : https://github.com/TomSwift/TSAlertView

How to show alert view when tab bar item is pressed and how to ignore it when used in a other target?

I have a UITabBar project with 5 tabs.
I am making 2 targets versions out of it: Free and a Paid version.
In the free version, when a user tries to navigate to tab item index 3 or 4, a UIAlertView should appear with a basic message like:
Do you want to upgrade?
YES / Cancel
When pressing Cancel button, the view should go to first view controller.
How should I do that?
Also, my next question, (I am aware that I should make another question here in Stack though) is how to prevent the UIAlertView from showing up in the paid version?
I have come as far as to use a button for UIAlertView for tab item 3 & 4 , but I don't want that.
The 2 targets are functioning well and I use the following code:
- (IBAction)openAlert:(id)sender
{
#ifdef FREE
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Attention"
message:#"Choose option"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Download Full version", nil];
[alertView show];
#endif
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex ==1) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://***.com"]]];
}
}
Any help would be appreciated.
On the cancel, to move to another UIViewController, you simply change the self.tabBarController object's setSelectedIndex
example:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
//Cancel button was clicked
[self.tabBarController setSelectedIndex:0];
break;
case 1:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://***.com"]]];
break;
}
}
As for the Free vs Paid, it's opinion-based.
One way which is basic is by using NSUserDefaults to remember whether the app is free version or paid version and handle your logic accordingly.
Set your appdelegate as the delegate of your tabbar controller and do this work in appdelegate or whereever
When the user press the cancel button then call
[yourTabbarController setSelectedIndex:0]
Write your code in the following delegate method to avoid alert in particular version(Paid/Free)
(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
For the first question, you need to make use of the value of the index of button clicked in the alert view inside (void)alertView: (UIAlertView )alertView clickedButtonAtIndex:(NSInteger)buttonIndex and check if the index of the button pressed is same as the index of the cancel button. Then you can programatically press the tab for the required view and go to that.
Before you load the alert pop up, check for the status of the app, paid or free. You can check the same in two ways, one is by storing the app purchase status on the device in NSUserDefaults, and other by means of a server authentication, though the server authentication would be a hinderance in the use of the app as it would take some time to get the response from the server and in case of no network connectivity, the user would not be able to use the paid features of the app.
In case the app is having the required paid status, simply let the view in the paid tab load else just display a black screen.
You can implement this check in the view controllers of the paid tabs. In viewWillAppear, implement this check for getting the payment status and then if the app is not a paid one, show a black view and present the alert message. Else if the app is paid, business goes as usual.

Ipad ShareKit's UIActionsheet Issue

The Sharekit's initial UIActionsheet displays the items Email, Twitter and Facebook and Cancel on Iphone
However the same code ported to Ipad now the Cancel option is missing on its UIActionsheet.
why is that.
Are you using the action sheet in a popover? The standard dismiss interaction for a popover is touching outside of it. There is rarely a "cancel" button in a popover action sheet, and Apple's HIG recommends against it.

Resources