UIAlertView Background issue? - iphone

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

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 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 insert text from text field into alert view

if I wanted to insert text from a text field into an alert view, wouldn't I use this code? Where the text should be, it says: . Thanks for your help!
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message: %#",textField.text delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
Use this:
... message:[NSString stringWithFormat:#"Message: %#",textField.text] ...

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

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.