当我们在ios中使用社交网络登录时,如何将一个视图控制器转到另一个视图控制器

时间:2015-08-28 13:19:48

标签: ios objective-c

嗨,我是Ios的新手,在我的应用程序中,当我们使用社交网络登录时,我试图将一个视图控制器移动到另一个视图控制器,就像我已经用twitter注册了我的应用程序

根据我的代码,当我们点击Twitter登录按钮时,Twitter登录页面将被加载到屏幕上,当我们点击该按钮时,我们会在Twitter登录页面上显示“AuthorizedApp”按钮我们获得用户详细信息

我们获得该用户详细信息后,我想移动另一页

注意: -

我的主要目的是当我们点击“AuthorizedApp”按钮然后我想移动另一页请帮帮我一个

根据我的代码,我得到例外: - 警告:尝试在窗口层次结构中显示其视图!

我的代码: -

#import "ViewController.h"
#import "FHSTwitterEngine.h"
#import "ViewController1.h"
#import "AppDelegate.h"

@interface ViewController ()<FHSTwitterEngineAccessTokenDelegate>
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
    [[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"XXXXXXXXXXXXXX" andSecret:@"XXXXXXXXXXXXXXXXXXXXXXXXXX"];
    [[FHSTwitterEngine sharedEngine]setDelegate:self];
    [[FHSTwitterEngine sharedEngine]loadAccessToken];

    //google plus login button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self
               action:@selector(loginOAuth)
     forControlEvents:UIControlEventTouchUpInside];
//    [button setImage:[UIImage imageNamed:@"twitter-icon.png"] forState:UIControlStateNormal];
    button.frame = CGRectMake(10, 390, 300, 30);
    button.backgroundColor = [UIColor redColor];

    CALayer * d = [button layer];
    [d setMasksToBounds:YES];
    [d setCornerRadius:20];
    [self.view addSubview:button];
}

- (void)loginOAuth {

    UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {

        NSLog(success?@"L0L success":@"O noes!!! Loggen failure!!!");
        NSLog(@"User name ---->>>%@",FHSTwitterEngine.sharedEngine.authenticatedUsername);
        NSLog(@"User id ------> %@",FHSTwitterEngine.sharedEngine.authenticatedID);
        [self movetoanotherview];
    }];
    [self presentViewController:loginController animated:YES completion:nil];
}

-(void) movetoanotherview{

     ViewController1 *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
    [dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentViewController:dvc animated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:0)

我认为这种情况正在发生,因为您正在创建一个视图控制器。视图控制器将在其范围的末尾与块一起消失。

尝试将dvc声明为.h文件中的属性(或.m文件的顶部)

@property (strong, nonatomic) ViewController1 *dvc;
Then do this instead:
self.dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
[_dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:_dvc animated:YES completion:nil];