将视图控制器链接到镜像
问题描述:
我的应用程序有一个Facebook登录屏幕,它在登录后显示个人资料图片,用户名,电子邮件和注销按钮。将视图控制器链接到镜像
我试图找出如何资料图片与的UIView或的UIImageView链接当前用户(这曾经是更适用,因为我用一个UIView称为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
所有张贴在这里的其他问题还没有真的帮了我 - 他们已经太模糊了。
如果有人可以告诉我如何将这个个人资料图片连接到一个UIImageView或UIView的HomeViewController那真是太棒了!我知道这很容易,我只是感到沮丧,这是给我这样一个问题
(我知道我需要使用prepareForSeuge方法,我只是不知道如何完成此语法的语法。)
答
它会帮助你。转到HomeViewController.xib,并通过拖动来放置UIView。
现在,选择该视图并在XCode的右侧单击第三个标识为Identity Inspector。这里设置类名为FBProfilePictureView
然后尝试。
答
如果你想diplay在FBProfilePictureView图像,然后
XIB /故事板 - >身份检查 - >类的名称 - > 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;
});
});
显示