On the Sign Up in my app I want to make sure that the user fill in one field. It should not matter which field for the user though. That's the problem I'm having. The closet I get is to force the user to fill in one specific textfield like the code below. And that's not the best UX i guess :) Anyone who know what to do?
self.saveButton.delegate = self;
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([self.RandomTextField.text isEqualToString:#""]) {
self.saveButton.enabled = NO;
} else {
self.saveButton.enabled = YES;
}
return YES;
}
- (IBAction)SignUPBtn:(UIButton *)sender {
if(txtName.text.length==0 && txtEmail.text.length==0 && txtPass.text.length==0)
{
[[[UIAlertView alloc] initWithTitle:#"" message:#"Please Fill Atleast One Field" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
}
else
{
//Write Your Code here. this else called only if anyone of three textfield is filled up.
}
}
in the click event of the sign_up button
- (IBAction)SignUPBtn:(UIButton *)sender {
if([textfeld_Email.text length]>0)
{
//sign up
}
else
{
if([textfeld_Pswd.text length]>0)
{
//sing up
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Please enter your email and pass" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
}
Related
I wonder if anyone is able to provide a code example of Parse login where the email address must be validated and also must be from a specific address. I believe it is something like;
[query whereKey:#"emailVerified" equalTo:[NSNumber numberWithBool:YES]];
and
[query whereKey:#"comment" containsString:#"#gmail.com"];
but I have been unable to get this working in my project.
Any help or suggestions would be great but a piece of code would be awesome
Below is my existing code which will not let an unverified email user login but now I want to add the email handle
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
if (![[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"User not validated email");
[[[UIAlertView alloc] initWithTitle:#"Access restricted" message:#"To access this area please validate your email address" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
else if ([[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"Email validated");
[self dismissViewControllerAnimated:YES completion:NULL];
[[[UIAlertView alloc] initWithTitle:#"Welcome back" message:(#"%#", user.username) delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
// [self dismissViewControllerAnimated:YES completion:NULL];
NSLog(#"Login sucessfull and username is %#",user.username);
}
Are you performing this check prior to allowing the user to login? If so the email being verified can be checked easily.
You can create a helper method with the following
- (void)methodname:(PFUser *)User {
if (![[user objectForKey:#"emailVerified"] boolValue]) {
// make sure user did not recently verify email address
[user refresh];
if (![[user objectForKey:#"emailVerified"] boolValue]) {
// handle how you want to tell user they need to verify email address
[self redirectWithMessage:#"You must verify your email address"];
return;
}
} else if {
// check for specific address and handle if doesn't meet that requirement
} else {
// The user verified and email is of correct address - send user to view
}
Working from cell phone, please excuse it not being in a full code block.
thanks for your suggestions and comments. I managed to solve it, for some reason could not work it out yesterday. The i believe answer is;
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
if (![[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"User refresh");
// make sure user did not recently verify email address
[user refresh];
if (![[user objectForKey:#"emailVerified"] boolValue])
NSLog(#"User not validated email");
[[[UIAlertView alloc] initWithTitle:#"Access restricted" message:#"To access this area please validate your email address" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
if (![[user objectForKey:#"email"] containsString:#"gmail.com"]) {
[[[UIAlertView alloc] initWithTitle:#"Error" message:#"You must have a validated gmail.com email to access this area." delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
NSLog(#"Email not verified or not a gmail email");
}
else if ([[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"Email validated");
[self dismissViewControllerAnimated:YES completion:NULL];
[[[UIAlertView alloc] initWithTitle:#"Welcome back" message:(#"%#", user.username) delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
// [self dismissViewControllerAnimated:YES completion:NULL];
}
if (user.objectForKey("emailVerified").boolValue == true){
println("true")
} else {
println("false")
}
I'm kinda stuck with a stupid problem, in my app when a user press on a TableViewCell he can change some value in the server, before i am sending the information to server i want to show UIAlertView to the user to make sure he wants to do that.
so in didSelectRowAtIndexPath:
i wrote this
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Caution!" message:#"bla bla " delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alert show];
then its calls the UIAlertView method clickedButtonAtIndex:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
NSString *url = #"some url";
NSDictionary *paramerter = #{#"parameter":parameter};
[self.jsonHandler startParseWithParameters:paramerter andUrlAdress:url withCompletion:^(int errValue) {
if (errValue == 1) {
NSLog(#"ERROR");
}else if (errValue == 0){
[self AlertViewWithTitle:#"success" andMessage:#"success"];
}
}];
}
}
the problem is that the if (buttonIndex == 0) called for every cell and change them all!
and i get UIAlertView message for every cell in the tableView.
how can i prevent it?
EDIT
Ok the problem caused because i use the same buttonIndex for both UIAlertViews
i solved it using this:
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"buttonString"]){
//Do what ever you need
}
hope someone find it helpful.
The selector 'go' with IBAction return type is not responding correctly. If the button is clicked with the text field being empty i.e its value being nil , the flow should return the 'if' part and not 'else'. But it works fine when I click the button second time. what can be the problem ?
Below is the code from implementation file i.e. ViewController.m where I have implemented the go selector.
#synthesize textField = _textField;
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
//Clear the text field
self.textField.text =nil;
}
NSString *s;
-(IBAction)go:(id)sender
{
[self.textField resignFirstResponder];
if (self.textField.text == nil)
{
s = [NSString stringWithFormat:#" Enter Your Name First " ];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Blank Field : "
message:s
delegate:self
cancelButtonTitle:#"OKAY"
otherButtonTitles:nil];
[alert show];
}
else
{
s = [NSString stringWithFormat:#"Hello %# " , self.textField.text];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello "
message:s
delegate:self
cancelButtonTitle:#"Thanks"
otherButtonTitles:nil];
[alert show];
}
}
Please help.
Thanks in advance.
Instead of using nil as your comparator I would instead use something more concrete like
if ([self.textfield.text length] > 0)
{
}
else
{
}
I have an error when I run my code: It says undeclared identifier of 'alertView' for this line of code:
-(void)alertView:(UIAlertView* )alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0)
else if(butonIndex==1)
}
Thank you for your help.
It goes something like the following.
- (void)dismissPop2:(NSString *)projectname {
projectdelete = projectname;
NSString *msg = [NSString stringWithFormat:#"Are you sure you want to delete this project (%#)?",projectname];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"- Project deletion -"
message:msg
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Delete", nil];
[alert setTag:100];
[alert show];
}
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView { // Validation
if ([alertView tag] == 100) {
return YES;
}
else {
return YES;
}
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([alertView tag] == 100) {
// Deleting a project
if (buttonIndex == 1) {
// Do something since the user has tapped YES
}
}
If it doesn't help, then you should show more work.
You likely have a syntax error earlier in your code that is breaking the parser. Check to make sure the function above the one you posted is closed with a }, all [] are matched, and statements end with a ;
If you post a bit more, someone could probably point it out, but I'm sure you can find it by reading your code.
I want to show a box and proceed with my code based on user's input. UIAlertView does not work as the application does not wait for the input. So is there another type of widget that can wait for user input and then pass control to the app ?
I know there are duplicates here but they are not very helpful as I seem to be missing some pieces (completely new to objective c...)
-(void)function1{
...
// Add UIAlertView *alert; to .h file
alert = [[UIAlertView alloc] initWithTitle:#"" message:#"" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView == alert && buttonIndex == 1){ // If yes
[self function2];
}
}
-(void)function2{
...
//Continue your task
}
you want a MODAL alert -- just use a UIAlertView and wait for its delegate before proceeding.
- a {
alert.delegate = self;
[alert show];
}
-alertView:(id)a didDismissWithButtonIndex:(int)i {
[self proceed];
}
- proceed {
... after alert ...
}