iphone 4 UIAlertView setAlertViewStyle unrecognized selector sent to instance - uialertview

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];

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..

UIAlertView Background issue?

I Using a Uialertview in my class.
Here is my code
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:#"message" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
But the problem is when I press the ok button, the alert hides, but the black background is still there.
Does anyone have the answer for this?
Try this.
UIAlertView * alertView = [[[UIAlertView alloc] initWithTitle:#"" message:#"message" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil] autorelease];
[alertView show];
In Your Code [[UIAlertView alloc]initWithTitle:nil #"message" should initWithTitle:#"message"
Such Like,
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Your Title" message:#"Your Message Body !!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
Try,
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"" message:#"message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alertView show];

how to show alert when values is null

I want to show alert when values is null i have titleCategory if it has value null then it should show alert
NSString*test=titleCategory;
if ([titleCategory isEqualToString:nil])
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Select Category " delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
FirstViewController*targetController=[[FirstViewController alloc]init];
[self.navigationController pushViewController:targetController animated:YES];
}
if(test == nil)
{
UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:#"" message:#"Test is null" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[alert show];
}
Do this:
if (!(titleCategory.length > 0) || titleCategory == nil )
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Select Category " delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
FirstViewController*targetController=[[FirstViewController alloc]init];
[self.navigationController pushViewController:targetController animated:YES];
[targetController release]; // if not ARC
}
Please Use this code:
if([titleCategory.text isKindOfClass:[NSNull class]]){
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Select
Category " delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else{
FirstViewController*targetController=[[FirstViewController alloc]init];
[self.navigationController pushViewController:targetController animated:YES];
[targetController release]; // if not ARC
}

UIAlertView not showing correctly in iPhone app

In iphone app i am using alertview to check the if textbox values is empty then it should show alert other wise move to next screen but when i also enter the values again alert view is shows i don't know what is the problem
It always shows if true if i also enter value then also
-(IBAction)buttonClick{
if (monthTextField.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (motionSicknessTextField.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (prescriptionTextField.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (otherMeansTextField.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (cereniaTextField.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (costToClientTextField.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (clinicMarkup.text=#"") {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enter values first" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else{
GraphsViewController*targetController=[[GraphsViewController alloc]init];
NSString*dogswithMotionSickness=motionSicknessTextField.text;
NSString*valueOne=cereniaTextField.text;
NSString*valueTwo=prescriptionTextField.text;
NSString*valueThree=otherMeansTextField.text;
NSString*valueFour=overtheCounterTextField.text;
cerenia=cereniaTextField.text;
NSString*costToClient=costToClientTextField.text;
NSString*clinicalMarkup=clinicMarkup.text;
perMonth=monthTextField.text;
targetController.perMonth=perMonth;
targetController.dogswithMotionSickness=dogswithMotionSickness;
targetController.valueOne=valueOne;
targetController.valueTwo=valueTwo;
targetController.valueThree=valueThree;
targetController.valueFour=valueFour;
targetController.cerenia=cerenia;
targetController.costToClient=costToClient;
targetController.clinicalMarkup=clinicalMarkup;
[self.navigationController pushViewController:targetController animated:YES];
}}
If you want to check empty strings, use :
if([monthTextField.text isEqualToString:#""])
OR
if(monthTextField.text.length > 0)
I define these two macros in my AppName-Prefix.pch file
#define IS_EMPTY_STRING(str) (!(str) || ![(str) isKindOfClass:NSString.class] || [(str) length] == 0)
#define IS_POPULATED_STRING(str) ((str) && [(str) isKindOfClass:NSString.class] && [(str) length] > 0)
This way I can check for both empty strings and nil string objects.
IS_EMPTY_STRING(myString);
also use
if ([motionSicknessTextField.text isEqualToString:#""] || [motionSicknessTextField.text isEqualTo:nil])
it is filter with nil and also blank object or value of textField

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

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];
}