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];
}
Related
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..
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];
I am new to iPad developer,
I am making Registration form in my iPad, when user click Submit button i want to validate my textfield whether it is empty or not, if it is empty then it will display alert No cannot be empty.
here is my code snippet but it is not working,
declaration:
UITextField* noTxtbox= [[UITextField alloc] initWithFrame:CGRectMake(250, 200, 180, 50)];
noTxtbox.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:noTxtbox];
Code:
if ([noTxtbox.text isEqualToString:#""]) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Enter your No !"
message:nil delegate:self
cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
Any help will be appreciated.
try using noTxtbox.text.length == 0
The problem could be due to white space. Check it by removing white space by :-
NSString * noTxtbox_text = [noTxtbox.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([noTxtbox_text isEqualToString:#""]) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Enter your No !"
message:nil delegate:self
cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
In my app i have reset button which delete all the data of tables and database.but before deleting i have to put alert view and ask the question as follows:
- (IBAction)resetData:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Bills Data Entry"
message:#"Are you sure want to reset data?" delegate:nil
cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[self databaseOpen];
NSString *deleteData=[NSString stringWithFormat:#"delete from tbl_Bills"];
[database executeQuery:deleteData];
NSLog(#"inert query: %#",deleteData);
NSLog(#"records deleted");
[table reloadData];
[database close];
// DO STUFF
}
}
This method is not called when i click on yes.
UIAlertView's delegate must not be nil if you want to invoke its delegate method.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Bills Data Entry"
message:#"Are you sure want to reset data?" delegate:self
cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
UIAlertView delegate must be set to self if you want to invoke its delegate method.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Bills Data Entry"
message:#"Are you sure want to reset data?"
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
When you are using Delegate method you are supposed to set "delegate: self" instead of nil.
UIAlertView *my_Alert = [[UIAlert alloc] initWithTitle:#"Title of Alert" message:#"Your
Message" delegate:self cancelButtonTitle:#"OK",
otherButtonTitles:nil,nil];
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];
}