Uistepper in Uialertview - iphone

How can I show UIStepper in UIAlertView? Also suggest me any other alternative to show UIStepper in pop-up.

Try this.. Hope it will help you
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)];
UIAlertView *alert =[[UIAlertView alloc]init];// you can set your frame according to ypur requirment
[alert addSubview:stepper];
[alert show];

A better way of inserting views in UIAlertView would be to add them as a subview
Try the following
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:#"\n\n" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
UIStepper* stepper = [[UIStepper alloc] init];
stepper.frame = CGRectMake(12.0, 5.0, 100, 10);
[alert addSubview:stepper];
[alert show];

Related

UITextField Validation not working

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

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

Adding activityindicatorin alertVIew

I want to add a activity indicator in alertView.
How to do this?
I think you can do by this -
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"title" message:#"\n\n" delegate:nil cancelButtonTitle:#"cancel" otherButtonTitles:nil];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0f, 50.0f, 20.0f, 20.0f)];
[activityIndicator startAnimating];
[alertview addSubview:activityIndicator];
[alertview show];
[alertview release];
[activityIndicator release];
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:#"Configuring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
Check the tutorial here

How to change the frame of AlertView in iPhone App...?

I want to Add TextBox on AlertView. But When i'm adding, it overlaps little with buttons on it...So i want to increase the height and width of alertview...Could Anybody tell any idea??
Try the following code:
UIAlertView alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Title", nil)
message:NSLocalizedString(#"Message\n\n\n", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(#"Cancel", nil)
otherButtonTitles:NSLocalizedString(#"OK", nil), nil];
UITextField textField = [[UITextField alloc] initWithFrame:CGRectMake(16.0, 100.0, 250.0, 25.0)];
textField.borderStyle = UITextBorderStyleRoundedRect;
[alertView addSubview:textField];
[textField release];
[alertView show];
[alertView release];
try this
UITextField *TextField = [[UITextField alloc] initWithFrame:CGRectMake(22.0, 50.0, 240.0, 30.0)];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Enter\n\n" message:#"" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView addSubview:TextField];
[alertView show];

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