Modal prompt class name in iOS? - ios

So I'm completely drawing a blank on the name of the class that draws one of these modal prompts with multiple options. I've attached a screenshot. It's the prompt that's confirming whether or not the user wants to sign out.

That's a UIActionSheet, Read UIActionSheet Class Reference.
Example
In your header, you need to add the <UIActionSheetDelegate> protocol. Then in your #implementation this is how you would call this specific sheet:
UIActionSheet * sampleSheet = [[UIActionSheet alloc] initWithTitle:#"Are you sure you'd like to sign out from Path?" delegate:self
cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Sign Out" otherButtonTitles:nil];
[sampleSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[sampleSheet showInView:self.view];
And this is how you would handle the sheet:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch ( buttonIndex )
{
case 0:
NSLog(#"User Chose Cancel");
break;
case 1:
NSLog(#"User Chose to Sign out.");
break;
}
}

You want UIActionSheet Class Reference

See UIActionSheet, I think that's the class you're looking for.

UIActionSheet *popupQuery;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//give the user an option to choose an image from their library or take a new photo...
popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Take Photo", #"Choose From Library", nil];
popupQuery.tag = 0;
}
else {
//give the user an option to choose an image from their library or take a new photo...
popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Choose From Library", nil];
popupQuery.tag = 1;
}
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:[self.view window]];
[popupQuery release];

Related

How to Clear UITextfield Text and Ok button in UIAlertView in IOS?

I Created Password Validation. Password created successfully it will show one UIAlertView and press when user presses the OK, the Password Text field will get clear. How to do that? Please any Example?
Add UIAlertViewDelegate protocol:
#interface YourViewController : UIViewController <UIAlertViewDelegate>
Show Alert View using :
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"TITLE_HERE"
message:#"ALERT_MESSAGE HERE."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
After user presses OK, this method will called automatically:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked OK
if (buttonIndex == 0) {
// do something here...
yourTextField.text = nil;
}
}
Your question is not clear. If you want the password field text to be empty after displaying the UIAlert, please add the following code to make your password filed empty.
yourTextField.text = ""
Here's an example.
if(passwordValid==YES)
{
UIAlertView *passwordValidated = [[UIAlertView alloc] initWithTitle:#"Password Validated!"
message:#"Your password is successfully validated. Press OK to continue"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
yourTextField.text = "";
[updateMessage show];

ActionSheet keeps appearing for every button

I have a method which throws up an actionSheet which is populated by an array.
The problem is that as soon as I place that method in the sender for 1 button, it fires off for every single button press.
I only want it to display for the one button (btnPortfolio).
Here is the code for my buttons:
- (IBAction)btnPortfolio:(id)sender {
[self populatePortfolioList];
}
- (IBAction)btnAdd:(id)sender {
}
- (IBAction)btnRefresh:(id)sender {
}
and here is my method:
-(void)populatePortfolioList{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Choose your option"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (NSString *title in portfolio_list) {
[actionSheet addButtonWithTitle:title];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:#"Cancel"];
[actionSheet showInView:self.view];
}
since you are using IBActions, I assume that you have somehow created the methods by ctrl+dragging from the buttons into your code? is that the case? it might be possible that you accidentally connected more than one of your buttons with the method btnPortfolio which causes populatePortfolioList to be called any time the button is pressed

How to hook UIAlertView to actions?

I am creating a drawing application where the user can draw using their finger strokes. I am trying to make a button that asks the user if they would like to clear the canvas. This alert has two buttons "Yes" and "No". I have the alert view appearing correctly but I have spent all day trying to figure out how to hook the buttons up to actions. I have so far had no success even after reading and watching from many instructional sources. From everything that I have read I can't understand why it would not be working. I have included UIAlertViewDelegate in my .h file also.
Here is my alert view:
- (IBAction)clearButton:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Clear Canvas"
message:#"Are you sure?"
delegate:nil
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes", nil];
[alert show];
}
Here is my clear canvas method:
- (void)clearCanvas:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
drawImage.image = nil;
}
Any help or pointers would be greatly appreciated! I'm self taught and still very much a beginner!
Thanks!
- (IBAction)clearButton:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Clear Canvas"
message:#"Are you sure?"
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes", nil];
[alert show];
}
Notice the difference in the delegate parameter. You must conform to the delegate you have declared in the .h
Secondly, use the delegate method -alertView:clickedButtonAtIndex

Prompt for user input and store the data

I just started iOS development, and now I'm stuck. I have a table cell, where the user cann see data. Next to it, there are two buttons. One to delete, one to edit. The edit part is where I'm stuck. I have a label field. When the user clicks on the edit button a prompt should come where the user can type in data. I already found something to do it. But there's no save button and I don't know how I could then save the variable to an NSString
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Name der neuen Liste" message:#"" delegate:self cancelButtonTitle:#"Abbrechen" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
I currently have this. lNow a prompt pops up, where I can write something, but not save. I just can press cancel afterwards. How do I work with user input in iOS? I don't want to use the label as an UITextField since it has to be clickable to perform another action.
Try this:
- (void)noteInput
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"input"
message:#"input"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Save", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
UITextField *noteText = [alertView textFieldAtIndex:0];
NSString *note = noteText.text;
}
}
Try adding a Save button in otherButtonTitles. Then, in your UIAlertViewDelegate:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// Save button pressed
}
}

Accessibility: On updating UIAlertView's message, the text that Voice over reads does not change?

Please refer the code below:
UIAlertView *progressAlertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
progressAlertView.message=#"Hello, I am the new one";
Voice over always reads "Message" and never reads the new message string set in the second line "Hello, I am the new one". There's no way to change this accessibility label of the bodyTextLabel control/subView of UIAlertView.
Any idea how to make UIAlertView change its accessibility labels after its alloc'ed?
Thanks,
-Shilpi
You can use accessibilityTraits as UIAccessibilityTraitUpdatesFrequently to read updated message.
it works like:
alertObj.accessibilityTraits = UIAccessibilityTraitUpdatesFrequently;
Thanks
use this way for set message of UIAlertView
UIAlertView *progressAlertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[alertView setMessage:#"Hello, I am the new one"];
[alertView show];
For More About UIAlertView Refer this
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
You can change the subviews of UIAlertView to change single attributes like the accessibility label:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test"
message:#"Message"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
// In a standard UIAlertView there are 2 UILabels and some buttons
// The UILabel with the message is always the 2nd object in the array
NSArray *subviews = alert.subviews;
UILabel *messageLabel = [subviews objectAtIndex:1];
[messageLabel setAccessibilityLabel:#"Some other text"];
With this code you only change the accessibility label, so that VoiceOver reads another text but the old text is shown.
In your case you should set the accessibility label to the same as you want to set the message of the UIAlertView.

Resources