显示用户登录Objective-c中的详细信息?

时间:2015-05-16 09:52:55

标签: ios objective-c

我正在开发小型应用程序,我希望显示当前登录的详细信息(ex.name , email id , phone number, and password)

我的问题是: -

在我的ViewController中,我有几个按钮,例如:登录,注册,设置和关于。 如果用户未登录设置按钮应该是禁用或非活动状态,它应该提醒“请登录以查看详细信息”如果用户登录,则应显示其注册的详细信息,例如名称,电子邮件,电话号码和密码 我怎样才能做到这一点 ?任何人都能帮我解决这个问题吗?

这是我的代码:

LoginViewController.M

#import "LoginViewController.h"
#import "ViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController
@synthesize userName;
@synthesize passWord;
@synthesize forgotEmailID;
@synthesize topStrip;
@synthesize backBtIB;
@synthesize loginBtIB;
@synthesize forgetBtIB;
@synthesize bgViewIB;
@synthesize loginTittle;

- (void)viewDidLoad {
    [super viewDidLoad];

    forgotEmailID.hidden=YES;
    [userName setAutocapitalizationType:UITextAutocapitalizationTypeWords];
    [passWord setAutocapitalizationType:UITextAutocapitalizationTypeWords];
    // Do any additional setup after loading the view.
    [self.view sendSubviewToBack:bgViewIB];

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
    [super touchesBegan:touches withEvent:event];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    userName.layer.cornerRadius=10.0f;
    userName.layer.masksToBounds=YES;
    userName.layer.borderColor =[[UIColor blackColor] CGColor];
    userName.layer.borderWidth = 5.0f;
    passWord.layer.cornerRadius=10.0f;
    passWord.layer.masksToBounds=YES;
    passWord.layer.borderColor =[[UIColor blackColor] CGColor];
    passWord.layer.borderWidth = 5.0f;

}



- (IBAction)backButton:(id)sender {
}

- (IBAction)loginButton:(id)sender {

    NSLog(@"email:%@",userName.text);
    NSLog(@"password:%@",passWord.text);

    if([userName.text isEqualToString:@""] || [passWord.text isEqualToString:@""])

    {
        UIAlertView* alertViewq = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Please enter all the details." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertViewq show];

    }

    else
    {
        NSString *getdetails = [NSString stringWithFormat:@"&email=%@&password=%@",userName.text,passWord.text];
        NSLog(@"get:%@",getdetails);
        NSData *getData = [getdetails dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[getData length]];


        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.example.com/login.php"]]];
        [request setHTTPMethod:@"GET"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
        [request setHTTPBody:getData];
        NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

        if (theConnection)
        {
        }
        else
        {
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }

        ViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeScreen"];
        [self presentViewController:NVC animated:YES completion:nil];
    }


}

#pragma mark - MFMessage Delegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    if (result == MFMailComposeResultSent)
    {
        NSLog(@"\n\n Email Sent");
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (IBAction)forgetPasswordButton:(id)sender
{
    NSLog(@"email:%@",forgotEmailID.text);

    if([forgotEmailID.text isEqualToString:@""])

       {
           UIAlertView* alertViewq = [[UIAlertView alloc] initWithTitle:@"Request Forgot Password" message:@"Please enter your Register e-mail ." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
          alertViewq.alertViewStyle=UIAlertViewStylePlainTextInput;
           [alertViewq show];

}

      }
@end

SettingVC.m

#import "SettingVC.h"

@interface SettingVC ()

@end

@implementation SettingVC
@synthesize emailField;
@synthesize nameField;
@synthesize phoneField;
@synthesize scrollView;
@synthesize passwordField;
@synthesize confirmPassField;

@synthesize bgView;
@synthesize topStrip;
@synthesize setingTittle;
@synthesize backBtIB;
@synthesize imageView1;
@synthesize nameLbl;
@synthesize emailLbl;
@synthesize phoneLbl;
@synthesize imageView2;
@synthesize passwordLbl;
@synthesize confirmpassLbl;
@synthesize infoTextView;
@synthesize imageView3;
@synthesize switchView;
@synthesize saveDetailsLbl;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
    [super touchesBegan:touches withEvent:event];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    appdelegate=[UIApplication sharedApplication].delegate;
    appdelegate.ifLogin = YES;

    [self.view sendSubviewToBack:bgView];



    [scrollView setScrollEnabled:YES];

    CGFloat scrollViewHeight = 0.0f;
    for (UIView* view in scrollView.subviews)
    {
        scrollViewHeight += view.frame.size.height;
    }
      [scrollView setContentSize:(CGSizeMake(305, 1100))];


    // Do any additional setup after loading the view.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (IBAction)BackButton:(id)sender {
}

- (IBAction)SaveButton:(id)sender {
    NSLog(@"name:%@",nameField.text);
    NSLog(@"email:%@",emailField.text);
    NSLog(@"phoneno:%@",phoneField.text);
    NSLog(@"password:%@",passwordField.text);

    /* if ([self isValidEmail:[emailTextField text]] == 1) {

     UIAlertView* alertViewq = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Please enter Valid email" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [alertViewq show];
     } */

    if([nameField.text isEqualToString:@""] || [emailField.text isEqualToString:@""] || [phoneField.text isEqualToString:@""] || [passwordField.text isEqualToString:@""])

    {

    }

    else
    {
        NSString *post = [NSString stringWithFormat:@"&name=%@&email=%@&phoneno=%@&password=%@",nameField.text,emailField.text,phoneField.text,passwordField.text];
        NSLog(@"post:%@",post);
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];


        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/Settings.php"]]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
        [request setHTTPBody:postData];
        NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

        if (theConnection)
        {
        }
        else
        {
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
    }

}

- (IBAction)LagoutButton:(id)sender {
}
@end

0 个答案:

没有答案