UIAlertView not allowing text input in iOS 10 - ios

I am trying to fix on iOS 7+ an alert allowing me to input a 4 digit code, at the moment, the prompt appears, but the input field is blank and does not allow me to put anything in.
The methods below are used to call the pin code option, starting with the segmentedAction as seen below;
-(void)segmentedAction:(id)sender{
UISegmentedControl *control = (UISegmentedControl *)sender;
NSString *pincode = [self.objSettingAdapter getPinCode];
NSString *patternCode = [self.objSettingAdapter getPatternCode];
NSInteger pincodetype = control.selectedSegmentIndex;
if ((![pincode length]>0) && pincodetype==0) {
[self takePinInputFromUser:#"Choose Your PIN Code"];
}else if((![patternCode length]>0) && pincodetype==1) {
[self takePatterInputFromUser:#"Draw Pattern"];
}else {
[self.objSettingAdapter setPinCodeType:control.selectedSegmentIndex];
}
}
-(void)buttonAction:(id)sender{
UIButton *btn = (UIButton *)sender;
NSString *pincode = [self.objSettingAdapter getPinCode];
NSString *patternCode = [self.objSettingAdapter getPatternCode];
if ([btn.titleLabel.text isEqualToString:#"Reset PIN"] && (![pincode length]>0)) {
[self takePinInputFromUser:#"Choose Your PIN Code"];
}else if ([btn.titleLabel.text isEqualToString:#"Reset Pattern"] && (![patternCode length]>0)) {
[self takePatterInputFromUser:#"Draw Pattern"];
}else {
[self.objSettingAdapter setPinCodeType:([btn.titleLabel.text isEqualToString:#"Reset PIN"] ? 0 : 1)];
}
}
-(void)takePinInputFromUser:(NSString *)title{
AlertPinCode *prompt = [AlertPinCode alloc];
prompt = [prompt initWithTitle:title message:#"\n\n" delegate:self cancelButtonTitle:#"Cancel" okButtonTitle:#"Done"];
[prompt show];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
AlertPinCode *alertPin = (AlertPinCode *) alertView;
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *userPin = [alertPin enteredText];
if ([userPin length]<4) {
[alertPin dismissWithClickedButtonIndex:0 animated:YES];
[self takePinInputFromUser:#"Chose 4 Digit PIN Code"];
}else {
[self.objSettingAdapter setPinCodeType:0];
[self.objSettingAdapter setPinCode:userPin];
}
}
}

Try the following.
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Title" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:nil];
__weak typeof(UIAlertController) *weakAlertController = alertController;
UIAlertAction *okAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
__strong typeof(UIAlertController) *strongAlertController = weakAlertController;
UITextField *digitTextField = [strongAlertController.textFields firstObject];
NSString *pinCode = digitTextField.text;
NSLog(#"pin code: %#", pinCode);
// Do something with the PIN code
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = #"Input 4 Digit PIN Code";
}];
[self presentViewController:alertController animated:YES completion:nil];

you can use UIAlertViewController

Related

How allow copy/paste/cut in UIAlertView? (iOS, Objective C)

I want to allow users to copy/cut but mainly PASTE data from other apps into my app. I need to allow them to paste data in UIAlertView, when they are logging to the app. How can i make it?
This is my code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:[NSString stringWithFormat:NSLocalizedString(#"enter_login", nil)]
delegate:self
cancelButtonTitle:#"Ok"
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeEmailAddress];
[[alert textFieldAtIndex:1] becomeFirstResponder];
[UserDefaultsServices resetLoginCredentials];
[UserDefaultsServices resetLoginData];
self.alertView = alert;
[alert show];
It does this:
show what my code does, I need to allow users to paste data in password TextField
You can use this answer for swift versions :
Objective C version of shared answer is :
- (IBAction)showAlert:(id)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Add New Name" message:#"Your message" preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = #"Name";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = #"Password";
textField.secureTextEntry = true;
}];
UIAlertAction *saveAction = [UIAlertAction actionWithTitle:#"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// here you can access your textfields' texts
NSString *textField1 = alertController.textFields[0].text;
NSString *textField2 = alertController.textFields[1].text;
NSLog(#"Saving %# %#", textField1, textField2);
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// here you can access your textfields' texts
NSString *textField1 = alertController.textFields[0].text;
NSString *textField2 = alertController.textFields[1].text;
NSLog(#"Canceled %# %#", textField1, textField2);
}];
[alertController addAction:saveAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
Above code work like this :

Set limit to UITextField in ObjectiveC

I am creating login screen using Objective C in which i want to implement validation for User name(E-Mail) and password.How to implement this in very simple way.
You can always make use textField shouldChangeCharactersInRange delegate to handle the number of characters allowed in textField. Have look at the solution provided below :) Hope it helps
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(textField == self.emailTextField){
if (textField.text.length < 30 || string.length == 0){
return YES;
}
else{
return NO;
}
}
}
EDIT
As per your comments you are not recieveing the textField delegates, so here is what you can do :)
In your ViewController, confirm the UITextFieldDelegate using,
YourViewController : UIViewController <UITextFieldDelegate>
In your viewDidLoad or ViewWillAppear set the textField delegate as self.
self.emailTextField.delegate = self;
If you click the Validate Button, set the validate button Action and see the below code,first check the two textfield empty or not, if you give text then again check its valid email type or not, then all conditions are true, then put your code and run,
-(IBAction)action:(id)sender
{
if (tfMail.text.length == 0 || tfPass.text.length == 0)
{
[self validatetextfield];
}
else if (![tfMail.text isEqualToString:#""])
{
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
//Valid email address
if ([emailTest evaluateWithObject:tfMail.text] == YES)
{
//Its validated put your success code,
}
else
{
UIAlertController *aler = [UIAlertController alertControllerWithTitle:#"Test!" message:#"Please Enter Valid Email Address. \nex. fdsjfkd#mail.com" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[aler addAction:action];
[self presentViewController:aler animated:YES completion:nil];
//not valid email address
}
}
}
Alert Message Method:
-(void) validatetextfield
{
if (tfMail.text.length==0) {
UIAlertController *aler = [UIAlertController alertControllerWithTitle:#"Email Field Empty!" message:#"Please Enter the Email" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[aler addAction:action];
[self presentViewController:aler animated:YES completion:nil];
[tfMail becomeFirstResponder];
}
else if (tfPass.text.length==0)
{
UIAlertController *aler = [UIAlertController alertControllerWithTitle:#"Password Field Empty!" message:#"Please Enter the Password" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[aler addAction:action];
[self presentViewController:aler animated:YES completion:nil];
[tfPass becomeFirstResponder];
}
}
its successfully working for me, hope its helpful.

How to change colour of picker text in xCode?

I've finally got two pickers into one viewcontroller and i've realised they're a little tricky to see because the background is dark. How do I go about changing the colour of the pickers text?
Here's my whole view controller M
//
// ViewController.m
// Repayment Calculator
//
// Created by Stewart Piper-Smith on 04/11/2015.
// Copyright (c) 2015 Stewart Piper-Smith. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
NSArray *_pickerViewArray;
NSArray *CareerViewArray;
#implementation ViewController
#synthesize button1, textbox1, textbox2, textbox3, startingsalary, repaymentlabel, debtlabel, startingrepayments, timetakentopayoffloan, realtimetakentopayoffloan, debtamounttextfield, annualrepaymentstextfield, monthlyrepaymentstextfield,weeklyrepaymentstextfield, payoffloantextfield, testlabel, annualrepaymentstest, totaldebtamounttest, writtenofflabel,payoffloanlabel,newlabel;
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// - (IBAction)button1Press:(id)sender {
// [button1 setTitle:textbox1.text forState:UIControlStateNormal];
// }
//The start of the calculate button that starts the calculations.
-(IBAction)menucontactbuttonPress:(id)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Error"
message:#"Contact Form Coming Soon"
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:#"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
-(IBAction)button1Press:(id)sender
{
[self.view endEditing:YES];
int x = ([textbox1.text intValue]);
int y = ([textbox2.text intValue]);
int q = ([textbox3.text intValue]);
float startingsal = ([startingsalary.text intValue]);
int debtamounttfield = ([debtamounttextfield.text intValue]);
float annualrepayments = ([annualrepaymentstextfield.text floatValue]);
//PROBLEM STARTS
float p1 = debtamounttfield /annualrepayments;//([debtamounttextfield.text intValue]);
if(isnan(p1) || isinf(p1)){
p1 = 0.00;
}
//int a = ([annualrepaymentstextfield.text intValue]);
//int b = ([debtamounttextfield.text intValue]);
//[newlabel setText:[NSString stringWithFormat:#"%#", a/b]];
[testlabel setText:[NSString stringWithFormat:#"%.01f",p1]];
[totaldebtamounttest setText:[NSString stringWithFormat:#"%d", debtamounttfield]];
[annualrepaymentstest setText:[NSString stringWithFormat:#"%#", annualrepaymentstextfield]];
[payoffloantextfield setText:[NSString stringWithFormat:#"%.01f", p1]];
//PROBLEM ENDS
[debtamounttextfield setText:[NSString stringWithFormat:#"£" "%i" , (x + y) * q]];
int arp = (startingsal - 17335)*0.09;
[annualrepaymentstextfield setText:[NSString stringWithFormat:#"£" "%i", arp ]];
if (arp < 0) {
annualrepaymentstextfield.text = #"Written Off";
}
int monthlyrepayments = (startingsal - 17335)*0.09/12;
[monthlyrepaymentstextfield setText:[NSString stringWithFormat:#"£" "%i", monthlyrepayments]];
if (monthlyrepayments < 0){
monthlyrepaymentstextfield.text = #"Written Off";
}
int weeklyrepayments = (startingsal - 17335)*0.09/12/4;
[weeklyrepaymentstextfield setText:[NSString stringWithFormat:#"£" "%i", weeklyrepayments]];
if (weeklyrepayments < 0){
weeklyrepaymentstextfield.text = #"Written Off";
}
//Error Handling
//Enter starting salary
if ([annualrepaymentstextfield.text isEqualToString: #"Written Off"]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Debt Written Off"
message:#"As it will take you longer than 30 years to pay off the loan, the debt would be written off."
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:#"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
if ([startingsalary.text isEqualToString: #""]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Error"
message:#"Please enter your expected starting salary"
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:#"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
//If course length is equal to 0
if ([textbox3.text isEqualToString: #"0"]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Error"
message:#"Your course lenth cannot be 0 Years. Please enter a different value"
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:#"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
//If course length text field is empty
if ([textbox3.text isEqualToString: #""]){
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Error"
message:#"Please enter your current course length"
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:#"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
//time taken to pay off loan > 20 years
int newtimetaken = [timetakentopayoffloan.text intValue];
if (newtimetaken <= 20) {
writtenofflabel.text = #"WO";
}
}
-(IBAction)clearbutton:(id)sender {
[textbox1 setText:[NSString stringWithFormat:#""]];
[textbox2 setText:[NSString stringWithFormat:#""]];
[textbox3 setText:[NSString stringWithFormat:#""]];
[startingrepayments setText:[NSString stringWithFormat:#"Loan at start of repayments: "]];
[startingsalary setText:[NSString stringWithFormat:#""]];
[realtimetakentopayoffloan setText:[NSString stringWithFormat:#""]];
[debtamounttextfield setText:[NSString stringWithFormat:#""]];
[annualrepaymentstextfield setText:[NSString stringWithFormat:#""]];
[monthlyrepaymentstextfield setText:[NSString stringWithFormat:#""]];
[weeklyrepaymentstextfield setText:[NSString stringWithFormat:#""]];
[payoffloantextfield setText:[NSString stringWithFormat:#""]];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Cleared"
message:#"All fields have now been cleared."
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:#"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
myLabel.text = #"Use the scroller above...";
datePickerView.delegate = self;
//CareerPickerView.dataSource = self;
_pickerViewArray = #[#"Before September 2012",#"After September 2012"];
CareerViewArray = #[#"1000",#"2000"];
CareerPickerView.delegate = self;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if(pickerView == datePickerView)
{
NSString *dateSelected = [_pickerViewArray objectAtIndex:row];
myLabel.text = dateSelected;
}
else if(pickerView == CareerPickerView)
{
NSString *careerSelected = [CareerViewArray objectAtIndex:row];
startingsalary.text = careerSelected;
}
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if(pickerView == datePickerView)
{
return _pickerViewArray.count;
}
else if(pickerView == CareerPickerView)
{
return CareerViewArray.count;
}
return 1;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if(pickerView == datePickerView)
{
return _pickerViewArray[row];
}
else if(pickerView == CareerPickerView)
{
return CareerViewArray[row];
}
return nil;
}
#end
You might require to implement UIPickerViewDelegate method -pickerView:attributedTitleForRow:forComponent:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *myTitle = #"my title";
NSAttributedString *myAttString = [[NSAttributedString alloc] initWithString:myTitle attributes:#{NSForegroundColorAttributeName:[UIColor whiteColor]}];
return myAttString;
}
Reference: iOS Documentation
Hope this helps.
you can use UIPickerView delegate method:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *title = self.pickerArray[row];
NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:#{NSForegroundColorAttributeName:NEON_GREEN}];
return attString;
}

UIAlertController Does Not Return User Input

I'm using UIAlertController for the first time. I need to prompt the user for an input. Anyway, the following is what I have.
- (void)showAlert {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Hello!" message:#"Type something.") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *noButton = [UIAlertAction actionWithTitle:#"Cancel") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
UIAlertAction *yesButton = [UIAlertAction actionWithTitle:#"Enter") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//NSString *input = alert.textFields[0].text;
//NSLog(#"input was '%#'", input);
UITextField *textField = alert.textFields[0];
NSLog(#"%#",textField.text); // <====== It's not returned
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
[textField addTarget:self action:#selector(alertTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[yesButton setEnabled:NO];
}];
[alert addAction:noButton];
[alert addAction:yesButton];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)alertTextFieldDidChange:(UITextField *)sender {
UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
if (alertController) {
UITextField *textfield = alertController.textFields.firstObject;
UIAlertAction *okAction = alertController.actions.lastObject;
okAction.enabled = [self validateName2:textfield.text:5]; // function for validating user input
}
}
For some reason, when the user tap Yes, the application doesn't return user input. In fact, Xcode dashes 'text' as in 'NSString *input = alert.textFields[0].text. A strange thing is that UIAlertView doesn't return user input. That's why I've switched to UIAlertController.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([alertView tag] == 101) {
if (buttonIndex == 1) {
NSString *username = [[alertView textFieldAtIndex:0] text];
NSLog(#"%#",username); // <====== It's never returned.
}
}
}
Anyway, I wonder what I'm doing wrong with UIAlertController?
Muchos thankos
p.s. I'm using Xcode 6.4 (6E35b). This issue may be caused by Xcode. If I debug the code with the iPad2 simulator, it'll actually return user input while it doesn't if I use the iPhone4S simulator.
Use this for textField in alertcontroller
__block typeof(self) weakSelf = self;
UIAlertController *alertController;
alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.tag = 1001;
textField.delegate = weakSelf;
textField.placeholder = #"";
[textField addTarget:weakSelf action:#selector(alertTextFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
}];
//OK Button
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:#"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
UITextField *textField = alertController.textFields.firstObject;
// Do stuff here
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
- (void)alertTextFieldDidChange:(UITextField *)sender
{
alertController = (UIAlertController *)self.presentedViewController;
if (alertController)
{
UITextField *textField = alertController.textFields.firstObject;
UIAlertAction *okAction = alertController.actions.lastObject;
okAction.enabled = textField.text.length > 0; // condition to enable button
}
}
#pragma mark - UITextField delegate methods
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
I would recommend using UITextFieldDelegate to handle the textField!
Set textField.delegate = self and then use the - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string method to do what you do in alertTextFieldDidChange if the replacementString has a length of > 0.
You are provided with delegate methods for UITextField so you don't have to create the selectors yourself, I recommend you use them to their fullest!
Here are the docs in case you want to know more! https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/

UIAlertController (UIAlertControllerStyleActionSheet) with iOS 7

In iOS 8 to get add photo alert functionality, I do:
UIAlertController * view= [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* choosePhoto = [UIAlertAction
actionWithTitle:#"Choose Exisiting"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[self selectPhoto];
}];
[view addAction:choosePhoto];
...
How can I do the same thing in iOS7?
UIAlertController does not work with iOS7.1 and UIAlertView does not provide such functionality.
As requested above, I answer my own question:
- (void)updateWithActionSheet:(BOOL)isNew
{
NSString *destructiveButtonTitle = nil;
if (!isNew) {
destructiveButtonTitle = #"Delete it";
}
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:destructiveButtonTitle
otherButtonTitles:#"Choose Exisiting", #"Take Photo", nil];
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:#"Cancel"]) {
[self.firstNameTextField becomeFirstResponder];
}
if ([buttonTitle isEqualToString:#"Choose Exisiting"]) {
[self selectPhoto];
}
if ([buttonTitle isEqualToString:#"Take Photo"]) {
[self takePhoto];
}
if ([buttonTitle isEqualToString:#"Delete it"]) {
[self deletePhoto];
}
}

Resources