hi I'm writing a code for an iPhone app in objective C and i want my button called SignUp when pressed by user to send alert message as shown is "-(void) registerNewUser" how can i do it? also how do i make it check for existing emails?? Thanks
#import "SignUpViewController.h"
@interface SignUpViewController ()
@end
@implementation SignUpViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.Password2.secureTextEntry=YES;
self.ReEnterPassword.secureTextEntry=YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)SignUp:(id)sender {
//check if all text fields are completed
if ([_Email.text isEqualToString:@""] ||[_Password2.text isEqualToString:@""] || [_ReEnterPassword.text isEqualToString:@""]) {
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You must complete all fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[error show];
}
else {
[self CheckPasswords];
}
}
- (void) CheckPasswords {
//check that the two apssword fields are identical
if ([_Password2.text isEqualToString:_ReEnterPassword.text]) {
NSLog(@"Passwords match!");
[self Agree];//call Action;
}
else {
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Passwords do not match" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[error show];
}
}
- (IBAction)Agree:(id)sender {
if(_Agree.selectedSegmentIndex == 0){
[self registerNewUser];
}
else{ UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You must accept Terms and Conditions" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[error show];
;}
}
- (void) registerNewUser {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//write the username and password and set BOOL value in NSUserDefaults
[defaults setObject:_Email.text forKey:@"Username"];
[defaults setObject:_Password2.text forKey:@"Password"];
[defaults setBool:YES forKey:@"Registered"];
[defaults synchronize];
if(_SignUp.buttonType == 1){
UIAlertView *success = [[UIAlertView alloc] initWithTitle:@"Success" message:@"You have registered a new user" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[success show];
}
}
@end
Aucun commentaire:
Enregistrer un commentaire