No known class method for selector when using blocks - ios

i am new to use block syntax and facing the below problem. The below code is calling another static method of a class that causing the problem. below code is called from click of next button on bar . is there any mistake on the syntax of this code?
-(BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if (![sender isKindOfClass:[UIBarButtonItem class] ]) {
return true;
}
// Trim the spaces
self.stewardsNameTextField.text = [self.stewardsNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
self.trackNameTextField.text = [self.trackNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
self.curatorNameTextField.text = [self.curatorNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ];
bool isValid =[JLTValidator validateFields: #[self.stewardsNameTextField, self.trackNameTextField, self.curatorNameTextField, self.weatherConditionSegment, self.trackConditionSegment] withScrollToCallback: ^(UIView * invalidField) // problem is here. Is this incorrect syntax?
{
if (invalidField == self.stewardsNameTextField || invalidField == self.trackNameTextField || invalidField == self.curatorNameTextField)
{
[invalidField becomeFirstResponder];
}
else
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
CGPoint top = CGPointMake(0, invalidField.frame.origin.y - 90);
[_scrollView setContentOffset:top animated:YES];
_scrollView.scrollIndicatorInsets=contentInsets;
}
if (!isValid) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry!" message:#"Please fill out the marked fields." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
return isValid;
}];
}
The definition of the static method being called to the class:
+(BOOL)validateFields:(NSArray *)fields
{
return [JLTValidator validateFields:fields withScrollToCallback:nil];
}
+(BOOL)validateFields:(NSArray *)fields andShouldDisplayMessage : (bool) shouldDisplayMessage
{
return [JLTValidator validateFields:fields withScrollToCallback:nil andShouldDisplayMessage:shouldDisplayMessage];
}
+(BOOL)validateFields:(NSArray *)fields withScrollToCallback : (void (^) (UIView *))scrollToCallback
{
return [JLTValidator validateFields:fields withScrollToCallback:scrollToCallback andShouldDisplayMessage:true];
}
+(BOOL)validateFields:(NSArray *)fields withScrollToCallback : (void (^) (UIView *))scrollToCallback andShouldDisplayMessage : (bool) shouldDisplayMessage
{
}
Whats wrong here? pls guide.

+(BOOL)validateFields:(NSArray *)fields withScrollToCallback : (void (^) (UIView *))scrollToCallback
The block parameter in this method doesn't return anything (you can see 'void' there). So if inside the block, you return BOOL value (isValid) is incorrect. Moreover, you returned the value that you're trying to get (isValid = ..... isValid) which is also a mistake.
I don't know what u're trying inside the block, but to solve this, you can do like below:
bool isValid =[JLTValidator validateFields: #[self.stewardsNameTextField, self.trackNameTextField, self.curatorNameTextField, self.weatherConditionSegment, self.trackConditionSegment] withScrollToCallback: ^(UIView * invalidField) // problem is here. Is this incorrect syntax?
{
if (invalidField == self.stewardsNameTextField || invalidField == self.trackNameTextField || invalidField == self.curatorNameTextField)
{
[invalidField becomeFirstResponder];
}
else
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
CGPoint top = CGPointMake(0, invalidField.frame.origin.y - 90);
[_scrollView setContentOffset:top animated:YES];
_scrollView.scrollIndicatorInsets=contentInsets;
}
}];
if (!isValid) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry!" message:#"Please fill out the marked fields." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}

Related

UIAlertView not calling

I'm attempting to create a simple webpage browser-esque application, where whenever the user wants to use a back, home, or forward function they are asked through an alert view to confirm.
The console window confirms that it has no problem calling the IBAction but comes up blank whenever I expect it to call Alert View.
Any help would be appreciated.
- (IBAction)controlPanelActions:(id)sender{
if (_controlPanel.selectedSegmentIndex == 0)
{
if ([_viewWeb canGoBack])
{
[self askToGoHome:nil];
}
}
- (IBAction)askToGoHome:(id)sender {
UIAlertView *alertDialog;
alertDialog.tag = 2;
alertDialog = [[UIAlertView alloc]
initWithTitle: #"Confirm"
message:#"Continue with Home Action?"
delegate: self
cancelButtonTitle: #"Yes"
otherButtonTitles: #"No", nil];
[alertDialog show];
}
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if (alertView.tag == 1)
{
if ([buttonTitle isEqualToString:#"Yes"])
{
NSLog(#"back - yes");
[_viewWeb goBack];
}
}
if (alertView.tag == 2)
{
NSLog(#"home - pre-yes");
if ([buttonTitle isEqualToString:#"Yes"])
{
NSLog(#"home - yes");
HOMEPAGEURL = [[NSURL alloc] initWithString:HOMEPAGE];
[self.viewWeb loadRequest:[NSURLRequest requestWithURL:HOMEPAGEURL]];
}
}
if (alertView.tag == 3)
{
if ([buttonTitle isEqualToString:#"Yes"])
{
[_viewWeb goForward];
}
}
}
You set alertDialog.tag = 2;before you call init.
So,everytime you set tag,you set tag to a nil.It will not work.
Alertview alloc and init method sets its tag to 0.
So alertDialog.tag = 2;
will not work.
add this line after alloc and init method.

How to set a selector method to a textfield for textchange in objective C?

I'm writing a signup view controller for my app. I needed to validate the form. I got the idea that setting a selector method for text value change should work for different textfields containing the form data.
I saw old questions and stuff on google and this is what I have so far
- (void)viewDidLoad
{
[super viewDidLoad];
self.passwordInput.secureTextEntry = YES;
self.btnDone.enabled = NO; //Done button needs to be disabled until form is properly validated
self.emailInput.delegate = self; //emailinput is the property attached to Email textfield of the form
self.passwordInput.delegate = self;
emailCheck = NO;
passwordCheck = NO;
[self.emailInput addTarget:self action:#selector(formValidation) forControlEvents:UIControlEventValueChanged];
[self.passwordInput addTarget:self action:#selector(formValidation) forControlEvents:UIControlEventValueChanged];
// Do any additional setup after loading the view from its nib.
}
-(void) formValidation {
NSString *regex = #"[^#]+#[A-Za-z0-9.-]+\\.[A-Za-z]+";
NSPredicate *emailPredicate = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", regex];
if(self.passwordInput.text.length >7)
{
passwordCheck = YES;
}
if([emailPredicate evaluateWithObject:self.emailInput.text])
{
emailCheck = YES;
}
if (self.passwordInput.text.length<7 || ![emailPredicate evaluateWithObject:self.emailInput])
{
self.warningLabel.text = #"Please enter a valid email/at least 8 character password";
}
if(passwordCheck == YES && emailCheck ==YES)
{
self.btnDone.enabled = YES;//button is enabled
} }
Now the problem is that the event is not firing off. Nothing happens when enter the data. Can anyone guide me what I'm doing wrong here?
P.s. i don't quite understand UITextFieldTextDidChangeNotification. If someone can suggest an alternative solution or explain that concept for me, it'd be awesome
I just tried forControlEvents:UIControlEventEditingChanged, the app crashes with error that it can't perform regular expression.**"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object <UITextField: 0x9ae8610;"**
Set the delegate of textfields and use the following method
-(void)textFieldDidEndEditing:(UITextField *)textField
{
[self validateForm:textField.text];
}
and change form validator function to
-(void) validateForm:(NSString *)inputString {
//validate inputString
}
on button submit click of form even you can check validation like below.
- (IBAction)pushToSignConfirmationScreen:(id)sender;
{
NSString *emailString = txt_Email.text;// storing the entered email in a string.
/ / Regular expression to checl the email format.
NSString *emailReg = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest=[NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailReg];
if ([txt_ContactName.text length] == 0 || [txt_Address.text length] == 0
|| [txt_DBAName.text length] == 0 || [txt_City.text length] == 0
|| [txt_Email.text length] == 0 || [txt_Phone.text length] == 0
|| [txt_State.text length] == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"All fields are required to begin setting up a merchant account." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
else if(([emailTest evaluateWithObject:emailString]!=YES)||[emailString isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"Enter your email in abc#example.com format." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
txt_Email.text = #"";
[btn_next setImage:[UIImage imageNamed:#"tag_icon_bt_up1.png"] forState:UIControlStateNormal];
return;
}
else if([txt_ZipCode.text length]!=5)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Warning" message:#"Please enter a valid zip code." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
txt_ZipCode.text = #"";
return;
}
else if([txt_Phone.text length]!=10 )
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Warning" message:#"Please enter a valid mobile number." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
txt_Phone.text = #"";
return;
}
First set the delegate for textfield, then do check in Method:-
- (BOOL)textFieldShouldReturn:(UITextField *)textField.
If textField is same then call your formValidation method.

UIButton disappearing after button click

When I click on a button in one row, the button in a different row disappears. Why might this be happening?
I looked at the following question and all the other questions within it, but nothing really answers my issue.
Custom, Imageless UIButton title disappears
I used the Debug Color Blended Layers to see if it's just a color thing, but my button just appears to disappear completely. I suspected this was a button.hidden property thing so I hardcoded button.hidden = NO; but nothing has changed.
What went wrong here?
Table Control Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([locationObjectsArray count] > 0)
{
return [locationObjectsArray count]+1;
}
else
return 1;
}
// Populate the Table View with member names
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier= #"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the Cell...
UIButton *selectButton = (UIButton *)[cell viewWithTag:1];
UILabel *cityNamesText = (UILabel *)[cell viewWithTag:2];
UIButton *editButton = (UIButton *)[cell viewWithTag:3];
//NSLog(#"[locationObjectsArray count]: %lu", (unsigned long)[locationObjectsArray count]);
if (indexPath.row >= [locationObjectsArray count]) {
// locationObjectsArray count == 0; Empty Array
cityNamesText.text = #"Add New Location";
NSLog(#"%ld: %#", (long)indexPath.row, #"Add New Location");
editButton.hidden = NO;
[editButton setTitle:#"Add" forState:UIControlStateNormal];
//[editButton setTitle:#"Add" forState:UIControlStateApplication];
selectButton.hidden = YES;
}
else if ([locationObjectsArray count] > 0) {
LocationObject *locObject = [locationObjectsArray objectAtIndex:indexPath.row];
NSLog(#"%ld: %#", (long)indexPath.row, [locObject getLocationName]);
cityNamesText.text = [locObject getLocationName];
selectButton.hidden = NO;
editButton.hidden = NO;
}
// Assign button tags
selectButton.tag = indexPath.row;
editButton.tag = indexPath.row;
[selectButton addTarget:self action:#selector(selectButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[editButton addTarget:self action:#selector(editButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
LocationObject *selectedLocationObject = [self loadLocationObjectWithKey:#"locObject"];
// Set Selected Cell to different Color
if ([cityNamesText.text isEqualToString:[selectedLocationObject getCityName]]) {
// Change to lightBlue color
UIColor * lightBlue = [UIColor colorWithRed:242/255.0f green:255/255.0f blue:254/255.0f alpha:1.0f];
[cell setBackgroundColor:lightBlue];
}
else
{
// All non-selected cells are white
//[cell setBackgroundColor:[UIColor whiteColor]];
//editButton.hidden = NO;
}
return cell;
}
// Select Button Clicked method
-(void)selectButtonClicked:(UIButton*)sender
{
if ([locationObjectsArray count] == 0)
{
NSLog(#"locObject count == 0");
// locationObjectsArray count == 0; Empty Array
// City name input is invalid
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"No Locations Set"
message:#"Please add a new location."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
else
{
NSLog(#"locObject count > 0");
if (sender.tag >= locationObjectsArray.count) {
// Create local isntance of the selected locationObject
LocationObject *locObject = [locationObjectsArray objectAtIndex:sender.tag];
// Set locObject as current default locObject
[self saveLocationObject:locObject key:#"locObject"];
}
[mainTableView reloadData];
}
}
// Edit Button Clicked method
-(void)editButtonClicked:(UIButton*)sender
{
if ([locationObjectsArray count] == 0) {
// locationObjectsArray count == 0; Empty Array
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Add Location"
message:#"Input City Name"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert addButtonWithTitle:#"Save"];
[alert show];
}
else
{
selectedObjectInArray = sender.tag;
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Edit Location"
message:#"Input City Name"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert addButtonWithTitle:#"Save"];
[alert show];
}
}
// Handle alertView
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if ([alertView.title isEqualToString:#"Add Location"]) {
// Add Location Alert View
if (buttonIndex == 0)
{
NSLog(#"You have clicked Cancel");
}
else if(buttonIndex == 1)
{
NSLog(#"You have clicked Save");
UITextField *cityNameTextField = [alertView textFieldAtIndex:0];
NSString *saveLocationName = cityNameTextField.text;
NSLog(#"saveLocationName: %#", saveLocationName);
if ([self isLocationValid:saveLocationName] == YES) {
NSLog(#"location is valid. locationObjectsArray.count = %lu", locationObjectsArray.count);
if (locationObjectsArray.count == 0) {
locationObjectsArray = [NSMutableArray array];
}
// City name input is valid
LocationObject *locObject = [[LocationObject alloc] init];
[locObject setCityName:saveLocationName];
locObject.byCityName = YES;
[locationObjectsArray addObject:locObject];
NSLog(#"After addObject: locationObjectsArray.count = %lu", locationObjectsArray.count);
[self saveLocationArrayObject:locationObjectsArray key:#"locationObjectsArray"];
[mainTableView reloadData];
}
else
{
// City name input is invalid
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"City Name Invalid"
message:#"Unable to locate input city."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
}
else if ([alertView.title isEqualToString:#"Edit Location"])
{
// Edit Location Alert View
if (buttonIndex == 0)
{
NSLog(#"You have clicked Cancel");
}
else if(buttonIndex == 1)
{
NSLog(#"You have clicked Save");
UITextField *cityNameTextField = [alertView textFieldAtIndex:0];
NSString *saveLocationName = cityNameTextField.text;
if ([self isLocationValid:saveLocationName]) {
// City name input is valid
int selectedIndex = (int)selectedObjectInArray;
LocationObject *locObject = [locationObjectsArray objectAtIndex:selectedIndex];
[locObject setCityName:saveLocationName];
[locObject setByCityName:(Boolean *)TRUE];
[locationObjectsArray setObject:locObject atIndexedSubscript:selectedIndex];
[self saveLocationArrayObject:locationObjectsArray key:#"locationObjectsArray"];
[mainTableView reloadData];
}
else
{
// City name input is invalid
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"City Name Invalid"
message:#"Unable to locate input city."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
}
}
Before:
After check button is selected:
Your issue is in these lines in cellForRowAtIndexPath:
// Assign button tags
selectButton.tag = indexPath.row;
editButton.tag = indexPath.row;
The tags will get mixed up as the cells are reused, I would recommend trying to omit using tags in this situation and use e.g. IBOutlets as #rdelmar pointed out.

Do not pass cursor to next textfield without entering value in first textfield

I have created textfields dynamically in UITableView I don't want to pass cursor without entering value in first textfield
[self.playerTable.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,BOOL*stop)
{
UITableViewCell *cell = obj;
if([cell isKindOfClass:[UITableViewCell class]])
{
for(UITextField *textField in cell.contentView.subviews)
{
if([textField isKindOfClass:[UITextField class]])
{
if ([textField isFirstResponder])
{
[textField resignFirstResponder];
isEditMode = NO;
if(!isEditMode && [playerstr length] > 0)
{
NSMutableArray *playerinfoArry = [dbWrapper getPlayerInfo];
for (Playerinfo *player in playerinfoArry)
{
if ([player.playername isEqualToString:playerstr])
{
isPlayerExist = YES;
isEditMode = !isEditMode;
CustomAlert *alert = [[CustomAlert alloc] initWithTitle:#"" message:#"Please choose a different name" delegate:nil cancelButtonTitle:nil otherButtonTitle:#""];
[_nameField resignFirstResponder];
[alert showInView:self.view];
NSIndexPath *indexPath1=[NSIndexPath indexPathForRow:selectedRow inSection:0];
[_playerTable selectRowAtIndexPath:indexPath1 animated:YES scrollPosition:UITableViewScrollPositionTop];
return;
}
}
}
}
}
}
}
}];
instead of looking for the first responder while trying to edit another UITextField, have you tried the other approach: not permitting the UITextField to resign as first responder. This could be something like:
- (BOOL) textFieldShouldEndEditing:(UITextField *)textField{
for(UITextField *otherTextField in self.view)
{
if ([otherTextField isKindOfClass:[UITextField class]] && [textField.text isEqualToString:otherTextField.text]){
CustomAlert *alert = [[CustomAlert alloc] initWithTitle:#"" message:#"Please choose a different name" delegate:nil cancelButtonTitle:nil otherButtonTitle:#""];
[alert showInView:self.view];
return NO;
}
}
return YES;
}
I hope this helps.

validation method doesn't gets called and segue doesn't gets triggered

I am trying to implement a sign up process with a parse backend. I have a validation method called processFieldEntries and once the done button gets enabled, I try to trigger the segue that I setup modally from my view controller(not from the done button) from view did appear method but neither the validation method gets called nor the segue gets triggered. I setup some debug and logging breakpoints for debugging but, I couldn't go any further apart from the fact that it does not see the view did load. I also tried setting up the segue from the done button. When I did that, the segue gets triggered, not from the code but from storyboard my storyboard here. If someone can help me to figure out how to call processfieldentriees along with the segue, I would really appreciate. Thank you.
NewUserSignUpViewController.h
#import <UIKit/UIKit.h>
#import "ProfileViewController.h"
#interface NewUserSignUpViewController : UIViewController<UITextFieldDelegate>
#property (strong, nonatomic) IBOutlet UIBarButtonItem *barButtonItem;
#property (strong, nonatomic) IBOutlet UITextField *usernameField;
#property (strong, nonatomic) IBOutlet UITextField *passwordField;
#property (strong, nonatomic) IBOutlet UITextField *repeatPasswordField;
- (IBAction)doneEvent:(id)sender;
- (IBAction)cancelEvent:(id)sender;
#end
NewUserSignUpViewController.m
#import "NewUserSignUpViewController.h"
#import "ProfileViewController.h"
#import <Parse/Parse.h>
#import "ActivityView.h"
#interface NewUserSignUpViewController ()
-(void)processFieldEntries;
- (void)textInputChanged:(NSNotification *)note;
- (BOOL)shouldEnableDoneButton;
#end
#implementation NewUserSignUpViewController
#synthesize barButtonItem = _doneButtonInTheBar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_usernameField];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_passwordField];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_repeatPasswordField];
}
-(void)viewDidAppear:(BOOL)animated
{
[_usernameField becomeFirstResponder];
[super viewDidAppear:animated];
//perform the segue
if (_doneButtonInTheBar.enabled == YES) {
[self performSegueWithIdentifier:#"segueToProfileView" sender:self];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
}
#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{ textField.delegate = self;
if (textField == _usernameField) {[_usernameField becomeFirstResponder];}
if (textField == _passwordField){[_passwordField becomeFirstResponder];}
if (textField == _repeatPasswordField)
{
[_repeatPasswordField becomeFirstResponder];
[self processFieldEntries];
}
return YES;
}
-(BOOL)shouldEnableDoneButton
{
BOOL enableDoneButton = NO;
if (_usernameField.text != nil && _usernameField.text.length != 0 &&_passwordField.text != nil &&
_passwordField.text.length !=0 && _repeatPasswordField.text != nil &&
_repeatPasswordField.text.length != 0) {
enableDoneButton = YES;
[self processFieldEntries];
}
return enableDoneButton;
}
-(void)textInputChanged:(NSNotification *)note
{
_doneButtonInTheBar.enabled = [ self shouldEnableDoneButton];
}
- (IBAction)doneEvent:(id)sender {
[_usernameField resignFirstResponder];
[_passwordField resignFirstResponder];
[_repeatPasswordField resignFirstResponder];
NSLog(#"processfieldentries");
[self processFieldEntries];
}
- (IBAction)cancelEvent:(id)sender {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)processFieldEntries
{
// Check that we have a non-zero username and passwords.
// Compare password and passwordAgain for equality
// Throw up a dialog that tells them what they did wrong if they did it wrong.
NSString *username = _usernameField.text;
NSString *password = _passwordField.text;
NSString *passwordAgain = _repeatPasswordField.text;
NSString *errorText = #"Please ";
NSString *usernameBlankText = #"enter a username";
NSString *passwordBlankText = #"enter a password";
NSString *joinText = #", and ";
NSString *passwordMismatchText = #"enter the same password twice";
BOOL textError = NO;
// Messaging nil will return 0, so these checks implicitly check for nil text.
if (username.length == 0 || password.length == 0 || passwordAgain.length == 0) {
textError = YES;
//setting the keyboard for th first missing output
if (passwordAgain.length == 0) {
[_repeatPasswordField becomeFirstResponder];
}
if (password.length == 0) {
[_passwordField becomeFirstResponder];
}
if (username.length == 0) {
[_usernameField becomeFirstResponder];
}
if (username.length == 0) {
errorText = [errorText stringByAppendingString:usernameBlankText];
}
if (password.length == 0 || passwordAgain.length == 0) {
if (username.length == 0) { // We need some joining text in the error:
errorText = [errorText stringByAppendingString:joinText];
}
errorText = [errorText stringByAppendingString:passwordBlankText];
}
}else if ([password compare:passwordAgain] != NSOrderedSame)
{errorText = [errorText stringByAppendingString:passwordMismatchText];
[_passwordField becomeFirstResponder];}
if (textError) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorText message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alertView show];
return;
// Everything looks good; try to log in.
// Disable the done button for now.
_doneButtonInTheBar.enabled = NO;
ActivityView *activityView = [[ActivityView alloc]initWithFrame:CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height)];
UILabel *label = activityView.label;
label.text = #"signing up";
label.font = [UIFont boldSystemFontOfSize:20.0f];
[activityView.activityIndicator startAnimating];
[activityView layoutSubviews];
[self.view addSubview:activityView];
// Call into an object somewhere that has code for setting up a user.
// The app delegate cares about this, but so do a lot of other objects.
// For now, do this inline.
NSLog(#"does it reach here");
PFUser *user = [PFUser user];
user.username = username;
user.password = password;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[error userInfo] objectForKey:#"error"] message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alertView show];
_doneButtonInTheBar.enabled = [self shouldEnableDoneButton];
[activityView.activityIndicator stopAnimating];
[activityView removeFromSuperview];
// Bring the keyboard back up, because they'll probably need to change something.
[_usernameField becomeFirstResponder];
return;
}
// Success!
[activityView.activityIndicator stopAnimating];
[activityView removeFromSuperview];
}];
}
}
#end
You could try not to use performSegueWithIdentifier inside viewDidAppear (performSegue actually take you to the other ViewController). Instead you could call it from an IBAction method connected to the done button, after calling in the same method processFieldEntries. I hope this can help you :)

Resources