Putting the text of a UITextField into a UIAlertView - iphone

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

Related

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

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

Iphone popup alert message

I can't find this anywhere. I don't want to have to use the debugger everytime. How do I get print messages on the iphone.
Use the NSLog function:
NSLog(#"Your message here.");
// with parameters:
NSString * myParam = #"Some value";
NSLog(#"myParam:%#", myParam);
The messages get written to the console log. You can view them in the simulator by running Console.app or by switching XCode to the Debugger/Console view (XCode -> Run -> Console)
If you really want to do a popup alert (like the javascript alert() function) you can do :
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test Message"
message:#"This is a sample"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
// 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];
Sample images:
UIAlertView* alert;
alert = [[UIAlertView alloc] initWithTitle:#"Info" message:#"Much more info" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
Look for UIAlertView with either Google or the Xcode Documentation Viewer.