Is it possible to display UIAlertView over another UIAlertView in iOS5 - iphone

I am getting password in First alertView and if the password is incorrect, then another alertView shows that the password is incorrect. Now the first alertView disappears. I wanna to display the second alertView over the first alertView.

This is not So complicated work i just done like this:-
UITextField *forgetPass;
-(IBAction)Password{// here is a Action for login password
//[txtEmail resignFirstResponder];
UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:#"Enter your password"];
[dialog setMessage:#" "];
[dialog addButtonWithTitle:#"Cancel"];
[dialog addButtonWithTitle:#"OK"];
dialog.tag= 1;
forgetPass = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
forgetPass.delegate = self;
[forgetPass setSecureTextEntry:YES];
forgetPass.placeholder = #"password";
forgetPass.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
[forgetPass setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:forgetPass];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 0.0);
[dialog setTransform: moveUp];
[dialog show];
}
-(void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alert.tag==1)
{
if (buttonIndex == 1) { // OK pushed
if([forgetPass.text length]>0 )
{
}
else {
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:#"Oops..!" message:#"please enter your current password" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
UITextField *forgetPass2 = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
forgetPass2.delegate = self;
[forgetPass2 setSecureTextEntry:YES];
forgetPass2.placeholder = #"password";
forgetPass2.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
[forgetPass2 setBackgroundColor:[UIColor whiteColor]];
[alert2 addSubview:forgetPass2];
forgetPass2.hidden=YES;
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 0.0);
[alert2 setTransform: moveUp];
alert2.tag=2;
[alert2 show];
[alert2 release];
}
}
if (buttonIndex == 0)
{
}
}
else if(alert.tag==2)
{
if (buttonIndex == 0)
{
[self Password];
}
}
}
i just create a demo for you might be its helps for please download this:-
http://www.sendspace.com/file/zptg8l

Related

Changing width and height of Alert Message i-Phone

Was wondering what the correct way would be to initialise my alert popup with a smaller window
-(void)alertMessage1:(NSString*) title:(NSString*) message1 {
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:#"Successfully uploaded!" message:message1 delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
}
You can create a UIAlertview as you suggested like this
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Title Here" message:#"Message here" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];
[alert release];
and if you want to adjust the frame them use
- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.f);
NSArray *subViewArray = alertView.subviews;
for(int x=0;x<[subViewArray count];x++){
if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
{
UILabel *label = [subViewArray objectAtIndex:x];
label.textAlignment = UITextAlignmentLeft;
}
}
}
In this alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.f); the CGRectMake(X-position, Y-Position, width, Height). Change it and your work will be done.
You should create custom AlertView or use one of these :
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=alertview
For the question you raised in comment changing the background color of UIAlertview you can add the background image like this directly. I am not sure if you can add the color or not.
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:#"Atention" message: #"YOUR MESSAGE HERE", nil) delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[theAlert show];
UILabel *theTitle = [theAlert valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
UIImage *theImage = [UIImage imageNamed:#"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[theAlert layer] setContents:[theImage CGImage]];

how to access the secureTextEntry for further use?

Hi I'm using the below code which includes the alertView containing UserID and Password field.
these UserID and Password are text field, i made password field as secure, but when i later want to access the data entered in password field, its showing no value in password field..
My code is
self.loginPassword = [[ UIAlertView alloc] initWithTitle:#"Please Login" message:#"Enter Valid UserID and Password\n\n\n\n" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Cancel", nil];
//[self.loginPassword setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
self.userIDText = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 80.0, 260.0, 25.0)];
self.userIDText.text=#"";
[self.userIDText setBackgroundColor:[UIColor whiteColor]];
[self.userIDText setKeyboardAppearance:UIKeyboardAppearanceAlert];
[self.userIDText setAutocorrectionType:UITextAutocorrectionTypeNo];
[self.userIDText setTextAlignment:UITextAlignmentLeft];
self.passwordField = [[UITextField alloc] initWithFrame:CGRectMake(12.0,115.0, 260.0, 25.0)];
self.passwordField.text=#"";
[self.passwordField setBackgroundColor:[UIColor whiteColor]];
[self.passwordField setKeyboardAppearance:UIKeyboardAppearanceAlert];
[self.passwordField setAutocorrectionType:UITextAutocorrectionTypeNo];
[self.passwordField setTextAlignment:UITextAlignmentLeft];
[self.loginPassword addSubview:self.userIDText];
[self.loginPassword addSubview:self.passwordField];
self.passwordField.secureTextEntry = YES;
[self.loginPassword setTag:2];
[self.loginPassword show];
[self.loginPassword release];
please suggest me some solution..
Create and In-built UIAlertView
UIAlertView *alert = [[UIAlertView alloc] init];
// Define Alertview Type to Login&Password
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
// Set Delegate to access Input Value
[alert setDelegate:self];
// show it
[alert show];
set Delegate in you interface (.h file) UIAlertViewDelegate
Implement This delegate method in your implementation (.m file)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Access your Username & Password from alertview and store them for further use.
NSString *username = [[alertView textFieldAtIndex:0] text];
NSString *password = [[alertView textFieldAtIndex:1] text];
NSLog(#"Username : %# , Password : %#",username, password);
}
This may help you.Just take a look at the code.
https://github.com/josecastillo/EGOTextFieldAlertView

UitextFields in UIAlertView selecting iOS

I have three UITextfields in UIAlertView, while tap on one UITextfield and try to tap on other its not selecting and creating a problem, also problem of resigning first responder, is it not good choice of using UITextfield in UIAlertView
- (IBAction)heightMethod:(id)sender
{
self.centimeterTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
centimeterTextField.placeholder = #" Centimeters";
self.centimeterTextField.delegate=self;
self.centimeterTextField.tag=3;
[ self.centimeterTextField setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview: self.centimeterTextField];
self.ptextfield = [[UITextField alloc] initWithFrame:CGRectMake(40, 80.0, 80, 25.0)]; ptextfield.placeholder = #" Feet";
self.ptextfield.delegate=self;
self.ptextfield.tag=4;
[self.ptextfield setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview:self.ptextfield];
self.ptextfieldInches = [[UITextField alloc] initWithFrame:CGRectMake(140, 80.0, 80, 25.0)]; ptextfieldInches.placeholder = #" Inches";
self.ptextfieldInches.delegate=self;
self.ptextfieldInches.tag=5;
[ptextfieldInches setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview:ptextfieldInches];
[self.centimeterTextField setKeyboardType:UIKeyboardTypeDecimalPad];
[self.ptextfieldInches setKeyboardType:UIKeyboardTypeDecimalPad];
[self.ptextfield setKeyboardType:UIKeyboardTypeDecimalPad];
self.alertHeight.tag=1;
[self.alertHeight show];
}
- (void) presentSheet {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Enter Information"
message:#"Specify the Name and URL" delegate:self cancelButtonTitle:#"Cancel"otherButtonTitles:#"OK", nil];
[alert addTextFieldWithValue:#"" label:#"Enter Name"];
[alert addTextFieldWithValue:#"http://" label:#"Enter URL"];
UITextField *tf = [alert textFieldAtIndex:0];
tf.clearButtonMode = UITextFieldViewModeWhileEditing;
tf.keyboardType = UIKeyboardTypeAlphabet;
tf.keyboardAppearance = UIKeyboardAppearanceAlert;
tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
tf.autocorrectionType = UITextAutocorrectionTypeNo;
// URL field
tf = [alert textFieldAtIndex:1];
tf.clearButtonMode = UITextFieldViewModeWhileEditing; tf.keyboardType = UIKeyboardTypeURL;
tf.keyboardAppearance = UIKeyboardAppearanceAlert; tf.autocapitalizationType = UITextAutocapitalizationTypeNone; tf.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show];
}
You can now create a UIAlertView with a style.
UIAlertView now has a property - alertViewStyle that you can set to one of the enum values
1. UIAlertViewStyleDefault
2. UIAlertViewStyleSecureTextInput
3. UIAlertViewStylePlainTextInput
4. UIAlertViewStyleLoginAndPasswordInput
Once you've created the alert view, you set it style and display it. After dismissing the alert, you can access the contents of the fields using the textFieldAtIndex property of the alert view.
or else you can use this one also.,
IAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:#"Enter Name"];
[dialog setMessage:#" "];
[dialog addButtonWithTitle:#"Cancel"];
[dialog addButtonWithTitle:#"OK"];
UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 70.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];
Hope this information helps. Thank you.

AlertView design (to format it with textfields)

I'm using an AlertView to make a login/password screen. I have some problem to format the view correctly. I want to have a AlertView as high as that want (check printscreen if I'm not clear ) but I don't know how!
Here's the code I've made :
// Ask for Username and password.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Login et mot de passe" message:#"" delegate:self cancelButtonTitle:#"Annuler" otherButtonTitles:#"Sauvegarder", nil];
// Adds a username Field
textfieldName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
textfieldName.placeholder = #"Login";
[textfieldName setBackgroundColor:[UIColor whiteColor]];
textfieldName.enablesReturnKeyAutomatically = YES;
[textfieldName setReturnKeyType:UIReturnKeyDone];
[textfieldName setDelegate:self];
[alertView addSubview:textfieldName];
// Adds a username
textfieldPassword = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 90.0, 260.0, 25.0)];
textfieldPassword.placeholder = #"Password";
[textfieldPassword setBackgroundColor:[UIColor whiteColor]];
textfieldPassword.enablesReturnKeyAutomatically = YES;
[textfieldPassword setReturnKeyType:UIReturnKeyDone];
[textfieldPassword setDelegate:self];
[alertView addSubview:textfieldPassword];
// Show alert on screen.
[alertView show];
[alertView release];
Alert view will adjust its contents (title and message) Try to add lines to the message:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Login et mot de passe"
message:#"\n\n\n\n\n" delegate:self cancelButtonTitle:#"Annuler"
otherButtonTitles:#"Sauvegarder", nil];

Adding an object to NSMutableArray from UITextField

With this code, I get this error:
'* -[NSMutableArray insertObject:atIndex:]: attempt to insert nil
object at 0'
categories=[[NSMutableArray alloc] init ];
UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:#"Category name"];
[dialog setMessage:#" "];
[dialog addButtonWithTitle:#"Cancel"];
[dialog addButtonWithTitle:#"OK"];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
[dialog show];
[dialog release];
[categories addObject:[nameField text]];
[nameField release];
[categoryTable reloadData];
When I run this in simulator, I get a crash before the alert view even pops up. Any ideas?
An exception will be raised in an NSArray if you try to add a nil object. Check for the condition first:
if ([nameField text]) [categories addObject:[nameField text]];
EDIT:
Also from your code, you need to implement the UIAlertViewDelegate protocol and attempt to add your object to your array there. For example:
- (void) showDialog {
UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:#"Category name"];
[dialog setMessage:#" "];
[dialog addButtonWithTitle:#"Cancel"];
[dialog addButtonWithTitle:#"OK"];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
[dialog show];
[dialog release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([nameField text]) [categories addObject:[nameField text]];
[categoryTable reloadData];
}
Assumes nameField and categories are iVars and you will need to release them when they are no longer needed. You should also check which button was pressed in the delegate method. HTH Dave