将视图控制器链接到镜像

时间:2015-06-19 22:29:49

标签: ios objective-c xcode facebook segue

我的应用程序有一个Facebook登录屏幕,登录后会显示个人资料图片,用户名,电子邮件和注销按钮

我想弄清楚如何将当前用户个人资料图片与 UIView UIImageView 相关联(这更适用,因为我使用的是一个名为<的UIView strong> FBProfilePictureView )在主VC中名为 HomeViewController 。以下是我对 LoginViewController 的代码,该代码包含要求和返回的FB信息。输入用户信息后,我也将它转到 HomeViewController

LoginViewController.h:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <FacebookSDK/FacebookSDK.h>

@interface LoginViewController : UIViewController <FBLoginViewDelegate>

@property (weak, nonatomic) IBOutlet FBLoginView *loginButton;

@property (weak, nonatomic) IBOutlet UILabel *lblLoginStatus;

@property (weak, nonatomic) IBOutlet UILabel *lblUsername;

@property (weak, nonatomic) IBOutlet UILabel *lblEmail;

@property (weak, nonatomic) IBOutlet FBProfilePictureView *profilePicture;

@property (strong, nonatomic) IBOutlet UIImageView *loginwallpaper;
@property (strong, nonatomic) IBOutlet UIImageView *loggedinwallpaper;

@property (strong, nonatomic) IBOutlet UIImageView *FBlogin;
@property (strong, nonatomic) IBOutlet UIImageView *FBlogout;

@end

这是 LoginViewController.m

#import "LoginViewController.h"

@interface LoginViewController ()

- (void)toggleHiddenState:(BOOL)shouldHide;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self toggleHiddenState:YES];
    self.lblLoginStatus.text = @"";

    self.loginButton.readPermissions = @[@"public_profile", @"email"];
    self.loginButton.layer.cornerRadius = 0;
    [self.loginButton.layer setBorderWidth:0.0f];

    self.loginButton.delegate = self;


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

-(void)toggleHiddenState:(BOOL)shouldHide{
    self.lblUsername.hidden = shouldHide;
    self.lblEmail.hidden = shouldHide;
    self.profilePicture.hidden = shouldHide;
    self.loggedinwallpaper.hidden = shouldHide;
    self.FBlogout.hidden = shouldHide;
}

-(void)toggleUnhiddenState:(BOOL)shouldShow{
    self.loggedinwallpaper.hidden = NO;
}

-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
    self.lblLoginStatus.text = @"";

    [self toggleHiddenState:NO];
    [self toggleUnhiddenState:YES];
}

-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
    self.lblLoginStatus.text = @"";

    [self toggleHiddenState:YES];
}

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
    NSLog(@"%@", user);
    self.profilePicture.profileID = user.objectID;
    self.lblUsername.text = user.name;
    self.lblEmail.text = [user objectForKey:@"email"];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *tabcontroller = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
    [self presentViewController:tabcontroller animated:YES completion:nil];
}

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

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

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

这里发布的所有其他问题对我没有帮助 - 他们太模糊了。

如果有人可以告诉我如何将此个人资料图片连接到 HomeViewController 中的UIImageView或UIView,这将是非常棒的!我知道这很容易,我很沮丧,这给了我这样的问题

(我知道我需要使用prepareForSeuge方法,我只是不确定如何完成此操作的语法。)

2 个答案:

答案 0 :(得分:0)

它会帮助你。转到HomeViewController.xib,然后拖动它来放置UIView。

现在,选择该视图,在XCode的右侧单击Identity Inspector的第三个选项卡。这里将类名设置为FBProfilePictureView然后尝试。

答案 1 :(得分:0)

如果你想在FBProfilePictureView中显示图像,那么

Xib / StoryBoard - &gt;身份检查员 - &gt;班级名称 - &gt; FBProfilePictureView

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
    NSLog(@"%@", user);
    self.profilePicture.profileID = user.id;
}

如果要在imageview中显示

queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);

 dispatch_async( queue, ^{


            // Load UImage from URL
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?width=200&height=200", user.id]];

            NSData *data = [NSData dataWithContentsOfURL:url];

            // Then to set the image it must be done on the main thread
            dispatch_sync( dispatch_get_main_queue(), ^{
                UIImage *image = [UIImage imageWithData:data];
                yourImageView.image =  image
                image = nil;
            });

        });