How to assign the alert message textfield input value to the button? - iphone

How to assign the alert message textfield input value to the button?
In the below code, I am assigning value to textfield but requirement is assign value to button instead of textfeild through alert message help me to solve the problem in iPhone.
-(IBAction)alertmessage{
[self setingValue];
}
-(void)setingValue{
myAlert = [[UIAlertView alloc] initWithTitle:#"Enter year" message:#"alert message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[myAlert addTextFieldWithValue:#"" label:#"entervalue"];
alertTextField=[myAlert textFieldAtIndex:0];
alertTextField.keyboardType=UIKeyboardTypeAlphabet;
alertTextField.clearsOnBeginEditing=YES;
alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
[myAlert show];
[myAlert release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:#"Ok"]) {
yearSelection.text= alertTextField.text;
}
}
if i enter keyboard value from alert textfield as input type that has to assign or appear on the button.

-(void)setingValue{
myAlert = [[UIAlertView alloc] initWithTitle:#"Enter year" message:#"alert message"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertTextField=[UITextfiled alloc]initwithFrame:CGRectFrame:(5,25,200,35)]; //set the frame as you need.
alertTextField.Placeholder=#"Enter Value";
alertTextField.keyboardType=UIKeyboardTypeAlphabet;
alertTextField.clearsOnBeginEditing=YES;
alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
[myAlert addSubview:alertTextFiedl];
[alertTextField release];
[myAlert show];
[myAlert release];
}

Related

Putting the text of a UITextField into a UIAlertView

Im trying to put the text from a textfield into a UIAlertView, but it's not shown. It is just showing blank.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Kik" message:self.kik.text delegate:self cancelButtonTitle:#"Got it!" otherButtonTitles: nil];
[alert show];
You should try,
if ( [self.kik.text length])
{
UIAlertView *alert = [UIAlertView alloc]initWithTitle:#"Kik" message:[NSString stringWithFormat:#"%#",self.kik.text] delegate:self cancelButtonTitle:#"Got it!" otherButtonTitles: nil];
[alert show];
}
else
{
UIAlertView *alert = [UIAlertView alloc]initWithTitle:#"Kik" message:#"Please enter a valid string" delegate:self cancelButtonTitle:#"Got it!" otherButtonTitles: nil];
[alert show];
}
Check..

How to show a UIAlertView upon selection of an item in UIPickerView

In my picker view i have a "Custom" option which should popup a UIAlertView for the user to enter a new value, the value is saved in the plist source of the picker for future reference. xxxEditingDidBegin is being called repeatedly (never ending).
I presume its because my UIAlertView is triggering the picker to close.
How should I have done this?
- (IBAction)serviceTypeFieldEditingDidEnd:(UITextField *)sender
{
UIPickerView *picker = [sender.inputView.subviews objectAtIndex:0];
NSString *selText = [serviceTypeArray objectAtIndex: [picker selectedRowInComponent:0]];
sender.text = selText;
if (NSOrderedSame==[selText compare:#"Custom"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Custom Role"
message:#"Enter Role Title"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
}
Implement method like
- (IBAction)doSelectDate:(UIDatePicker *)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Hi" message:#"AlertView is shwoing" delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
and connect above method with ValueChanged Event of UIPickerView;
I fixed it like this
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *rowString = [serviceTypeArray objectAtIndex:row];
if ([rowString compare:#"Custom"] == NSOrderedSame)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Custom Role"
message:#"Enter Role Title"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
else
{
_serviceType.text = rowString;
}
}

iphone 4 UIAlertView setAlertViewStyle unrecognized selector sent to instance

I used the below code to add textfield in UIAlertView. It works fine in Simulator(iOS SDK 5.0) but when i install in device(iOS 4.0.1) i get "Unrecognized selector sent to instance error"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter your name" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 9001;
[alert show];
[alert release];
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"My Test Alert" message:#"what do you want" delegate:nil cancelButtonTitle:#"tell me" otherButtonTitles:#"Cancel", nil];
[myAlert addTextFieldWithValue:#"nothing" label:#"say something"];
UITextField * aTextFld = [myAlert textFieldAtIndex: 0];
aTextFld.clearButtonMode = UITextFieldViewModeWhileEditing;
aTextFld.autocorrectionType = UITextAutocorrectionTypeNo;
[myAlert show];
[myAlert release];
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Hello!" message:#"Please enter your name:" delegate:self cancelButtonTitle:#"Continue" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
alertTextField.placeholder = #"Enter your name";
[alert show];
[alert release];
Include the library from here: http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
Try to use the below code:
AlertPrompt *prompt = [AlertPrompt alloc];
prompt.tag = 100;
prompt = [prompt initWithTitle:#"Enter a name" message:#" " delegate:self cancelButtonTitle:#"Cancel" okButtonTitle:#"Save"];
[prompt show];
[prompt release];

How to change UIAlertView cancel button text

I would like to know that how to change UIAlert's cancel button text during runtime.
- (void)showAlertWithTitle:(NSString*)title message:(NSString*)message cancelButtonTitle:(NSString*)cancelTitle {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:nil];
[alertView show]
[alertView release];
}

UIAlert View-for yes/no condition

my app needs alert msg and with yes button click another alert msg which decides the final action.
I have used - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
this method.
Please help me.
Do what #Adrian Pirvulescu said but before showing the alert do alert.tag = 1; and then when - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex is called do:
if (alertView.tag == 1) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"2nd Alert"
message:#"My message" delegate:self cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
alert.tag = 2;
[alert show];
[alert release];
}
else if (alertView.tag == 2) {
[self CallSomeMethod];
}
else {
//do what ever you want here
}
Check this out
http://www.timeister.com/2010/06/objc-show-alert-iphone/
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"UIAlertView"
message:#"My message" delegate:self cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alert show];
[alert release];