iPhone SDK simple alert message question - iphone

char asd='a';
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Are you sure?" message:asd
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
above code not compiling in iPhone simulator.
Why is that?
:)

You're trying to pass a char where an NSString is expected. Read up on Objective-C and th Cocoa/Cocoa Touch documentation.
To fix your issue, try this:
NSString *asd = #"a";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Are you sure?" message:asd
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert show];
[alert release];

You don't compile in the iPhone
simulator, you compile on your mac.
Do you get an error message?
The message parameter should be an NSString, not a char?

replace
char asd='a';
With
NSString *asd=#"a";
It should compile after it...

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

use UIAlertView when camera is running in iPhone

I'm trying to trigger an AlertView when my camera detect a face using OpenCV. I manage to do the face detection and can output an NSLog successfully. But when I tried to trigger the alert view with
NSLog(#"Face Detected");
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Face Detected" message:#"Do you really want to try again?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil] autorelease];
[alert addButtonWithTitle:#"Yes"];
[alert show];
[alert release];
I can see the Alert View is kind of triggered as the screen is dimmed but I could never see the alert view came out...
Thanks for helping!
Remove [alert release]. You already called autorelease on it.
Also, you can integrate [alert addButtonWithTitle:#"Yes"]; in the initializer:
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Face Detected"
message:#"Do you really want to try again?"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil] autorelease];
where are you calling this from ? Main thread or secondary ?
Because UIKit stuff should always been done on main thread.
Code example:
- (void)opencvFaceDetect
{
// stuff before
[self performSelectorOnMainThread: #selector(openAlertView) withObject:nil waitUntilDone:false];
// stuff after
}
and then
- (void)openAlertView
{
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Face Detected"
message:#"Do you really want to try again?"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil] autorelease];
}

objective-c : iphone programming : Showing variables on UIAlert view

i want simply to show a double value on a uialert view it is possible?
Put the value into a formatted NSString and send that to the alertView:
NSString *messageString = [NSString stringWithFormat:"#number = %.2f", 42.0];
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Title text" message:messageString delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
How are you showing the UIAlertView now? Something like the following should work:
double myDouble = 12.6;
NSString *alertString = [NSString stringWithFormat:#"%g", myDouble];
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:alertString
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[myAlert show];

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.