私人屏幕segue?

时间:2014-12-16 22:47:52

标签: ios

我有一个用户可以在我的应用中使用的基本登录/注册字段。我还要启动一个私有屏幕:一个新的视图控制器,用户可以在点击登录/注册按钮后看到。如果有能力登录或在应用程序中注册的人可以帮助我以编程方式为一个名为UserViewController的viewcontroller指定一个segue,我将不胜感激。

-(IBAction)btnLoginRegisterTapped:(UIButton*)sender {
//form fields validation
if (fldUsername.text.length < 4 || fldPassword.text.length < 4) {
    [UIAlertView error:@"Enter username and password over 4 chars each."];
    return;
}
//salt the password
NSString* saltedPassword = [NSString stringWithFormat:@"%@%@", fldPassword.text, kSalt];
//prepare the hashed storage
NSString* hashedPassword = nil;
unsigned char hashedPasswordData[CC_SHA1_DIGEST_LENGTH];
//hash the pass
NSData *data = [saltedPassword dataUsingEncoding: NSUTF8StringEncoding];
if (CC_SHA1([data bytes], [data length], hashedPasswordData)) {
    hashedPassword = [[NSString alloc] initWithBytes:hashedPasswordData length:sizeof(hashedPasswordData) encoding:NSASCIIStringEncoding];
} else {
    [UIAlertView error:@"Password can't be sent"];
    return;
}
//check whether it's a login or register
NSString* command = (sender.tag==1)?@"register":@"login";
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command", fldUsername.text, @"username", hashedPassword, @"password", nil];
//make the call to the web API
[[API sharedInstance] commandWithParams:params onCompletion:^(NSDictionary *json) {
    //result returned
    NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];
    if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"IdUser"] intValue]>0) {
        [[API sharedInstance] setUser: res];
        [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
        //show message to the user
        [[[UIAlertView alloc] initWithTitle:@"Logged in" message:[NSString stringWithFormat:@"Welcome %@",[res objectForKey:@"username"]] delegate:nil cancelButtonTitle:@"Close" otherButtonTitles: nil] show];
    } else {
        //error
        [UIAlertView error:[json objectForKey:@"error"]];
    }
}];

}

1 个答案:

答案 0 :(得分:0)

http://www.raywenderlich.com/81879/storyboards-tutorial-swift-part-1

查看该教程。你似乎在随着时间的推移做出决定 - 从来都不是一个好学的方法。

没有“私有”视图控制器,你所拥有的是一个视图控制器,没有登录就看不到。

您需要的流程是:

设置auth view controler(用户名,密码,[登录]按钮)

将登录按钮绑定到方法

将代码放入该方法以检查凭据的有效性

如果它们有效,则使用segue

显示新VC