2013-12-17 39 views
-1

用户在惠普Facebook上歌唱我的应用后,我不会显示他的名字和个人资料照片,我从AppDelegate类获取数据并将其添加到视图中的属性(UserNameLable)控制器,在ios应用程序中显示facebook用户的详细信息

在AppDelegate中所有nslogs显示视图控制器nslogs数据
显示空
我如何能在大声对我在mainViewController属性的数据?

在AppDelegate中这是代码

AppDelegate.h

@property (retain, nonatomic) NSString *first_name_property; 

AppDelegate.m

- (void)sessionStateChanged:(FBSession *)session 
         state:(FBSessionState) state 
         error:(NSError *)error 
{ 
    switch (state) { 
     case FBSessionStateOpen: 

      [[NSNotificationCenter defaultCenter] 
      postNotificationName:SCSessionStateChangedNotification 
      object:session]; 


       [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { 

        if (error) { 

         NSLog(@"error"); 
        } 

        else 
        { 
         NSLog(@"FB user first name:%@",user.first_name); 
         NSLog(@"FB user last name:%@",user.last_name); 

         // Add the data to the property I crated 
         first_name_property = user.first_name; 


        } 
       }]; 



      } 

      break; 
     case FBSessionStateClosed: 
     case FBSessionStateClosedLoginFailed: 
      [FBSession.activeSession closeAndClearTokenInformation]; 
      break; 

     default: 
      break; 

//这是在显示数据的代码我查看

mainViewController.h

@property (strong, nonatomic) IBOutlet UILabel *UserNameLable; 

mainViewController.m

-(void)viewDidAppear:(BOOL)animated{ 

    if (!UserNameLable) { 
     UserNameLable.text=((AppDelegate *)[UIApplication sharedApplication].delegate).first_name_property; 

    } 
    else{ 
     [email protected]"not set";} 
} 
+0

你在哪里加载mainViewController。在AppDelegate.m上设置first_name_property后,应该在sessionStateChanged上调用它。 mainViewController是facebook必须异步的地方。 – Shad

回答

3

使用first_name_property代替FIRST_NAME。

尝试

UserNameLable.text=((AppDelegate *)[UIApplication sharedApplication].delegate).first_name_property; 
+0

是的,这是我在做什么,仍为空。 – Bar

相关问题