以编程方式从视图控制器传递到另一个iOS

时间:2015-07-16 11:17:47

标签: ios objective-c viewcontroller

当我获得Facebook数据时,我试图以编程方式从视图控制器传递到另一个,有没有办法做到这一点? 通过使用我的方法,应用程序崩溃,在日志中我有:

  

2015-07-16 13:16:14.125 LoginSampleFB [1059:60b]警告:尝试   目前的视图不在窗口层次结构中! 2015-07-17   13:16:14.129 LoginSampleFB [1059:60b]异常' NSRangeException'   抓住!原因:'无法移除关键路径的观察者"隐藏"从   因为它没有注册为观察员。' 2015-07-16 13:16:14.171   LoginSampleFB [1059:60b] *断言失败 - [UIWindowController   过渡:fromViewController:toViewController:目标:didEndSelector:动画:],   /SourceCache/UIKit/UIKit-2935.137/UIWindowController.m:223 2015-07-16   13:16:14.172 LoginSampleFB [1059:60b] * 由于终止应用程序   未被捕获的异常' NSInternalInconsistencyException',原因:   '尝试从a开始模态转换   转型已在进行中。等待   viewDidAppear / viewDidDisappear知道当前的转换有   完成'   ***第一次抛出调用堆栈:(0x185e6ef50 0x1923781fc 0x185e6ee10 0x1869a6db4 0x188f2e5b8 0x188f2da9c 0x1000fabb8 0x1869e42d0   0x185e2f554 0x185e2f1c4 0x185e2ceec 0x185d6dc20 0x18ba55c0c   0x188e9efdc 0x1000fded8 0x19296baa0)libc ++ abi.dylib:终止于   NSException类型的未捕获异常

这是代码:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {

    NSString *userName = user.name;
    userName = [userName stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString *userNameOk = userName;
    NSString *userId = [user id];
    NSString *userEmail = [user objectForKey:@"email"];

    NSString *label_name = user.name;
    _profilePicture.profileID = ((dashBoardViewController*)self.tabBarController).id;
    _profilePicture.layer.cornerRadius = _profilePicture.frame.size.width / 2;
    _profilePicture.clipsToBounds = YES;
    _profilePicture.layer.borderWidth = 3.0f;
    _profilePicture.layer.borderColor = [UIColor whiteColor].CGColor;

    //self.lblEmail.text = [user objectForKey:@"email"];

    ((dashBoardViewController*)self.tabBarController).first_name = userNameOk;
    ((dashBoardViewController*)self.tabBarController).id = userId;

    dashBoardViewController *dashBoardViewController =     [self.storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
    dashBoardViewController.first_name = userNameOk;
    dashBoardViewController.label_name= userName;
    dashBoardViewController.id = userId;
    dashBoardViewController.userEmail = userEmail;
    [self presentModalViewController:dashBoardViewController animated:YES];

   }

修改

这是完整的代码

#import "ViewController.h"
#import "dashBoardViewController.h"
#import "BFPaperTabBarController.h"
#import <FacebookSDK/FacebookSDK.h>


@interface ViewController ()



@end

@implementation ViewController



- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    self.loginButton.delegate = self;
    self.loginButton.readPermissions = @[@"public_profile", @"email", @"publish_actions"];
     self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];

}

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


/*-(void)viewDidAppear:(BOOL)animated {

      dashBoardViewController *dashBoardViewController =     [self.storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"];

   NSString *USR = ((dashBoardViewController*)self.tabBarController).first_name;
     NSLog(USR);
    if (USR != @"0") {

        NSLog(USR);
        NSLog(@"USR DIVERSO DA 0");

        [self presentModalViewController:dashBoardViewController animated:YES];
    }

}*/

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {

    NSString *userName = user.name;
    userName = [userName stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString *userNameOk = userName;
    NSString *userId = [user id];
    NSString *userEmail = [user objectForKey:@"email"];

    NSString *label_name = user.name;
    _profilePicture.profileID = ((dashBoardViewController*)self.tabBarController).id;
    _profilePicture.layer.cornerRadius = _profilePicture.frame.size.width / 2;
    _profilePicture.clipsToBounds = YES;
    _profilePicture.layer.borderWidth = 3.0f;
    _profilePicture.layer.borderColor = [UIColor whiteColor].CGColor;

    //self.lblEmail.text = [user objectForKey:@"email"];

    ((dashBoardViewController*)self.tabBarController).first_name = userNameOk;
    ((dashBoardViewController*)self.tabBarController).id = userId;

    dashBoardViewController *dashBoardViewController =     [self.storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
    dashBoardViewController.first_name = userNameOk;
    dashBoardViewController.label_name= userName;
    dashBoardViewController.id = userId;
    dashBoardViewController.userEmail = userEmail;
    [self presentModalViewController:dashBoardViewController animated:YES];

   }


-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
    NSLog(@"%@", [error localizedDescription]);
}

-(IBAction)Skip:(id)sender{

    NSString *userName = @"0";
    NSString *userNameOk = userName;
    NSString *userId = @"0";
    NSString *userEmail = @"0";

    NSString *label_name = @"Loggati";
    _profilePicture.profileID = ((dashBoardViewController*)self.tabBarController).id;
    _profilePicture.layer.cornerRadius = _profilePicture.frame.size.width / 2;
    _profilePicture.clipsToBounds = YES;
    _profilePicture.layer.borderWidth = 3.0f;
    _profilePicture.layer.borderColor = [UIColor whiteColor].CGColor;

    //self.lblEmail.text = [user objectForKey:@"email"];

    ((dashBoardViewController*)self.tabBarController).first_name = userNameOk;
    ((dashBoardViewController*)self.tabBarController).id = userId;

    dashBoardViewController *dashBoardViewController =     [self.storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
    dashBoardViewController.first_name = userNameOk;
    dashBoardViewController.label_name= userName;
    dashBoardViewController.id = userId;
    dashBoardViewController.userEmail = userEmail;
    [self presentModalViewController:dashBoardViewController animated:YES];

}

@end

0 个答案:

没有答案