将数据发送到所选的视图控制器
Send Data to View Controller of choice
我正在尝试执行一些我知道很简单的事情,但我不确定语法。
首先,我让用户输入 Facebook 登录信息,让他们登录。然后我的代码提取他们的个人资料图片、用户名、电子邮件和 Facebook 按钮,并将其显示在 "LoginiewController" 中。 prof pic 是一个名为 profilePicture 的视图控制器,用户名为 lblUsername,电子邮件为 lblEmail, FB 按钮名为 loginButton。
ALL 我想做的是编写一些代码,将这 4 个值发送到 ProfileViewController,这不是 segue 的下一个视图控制器,以便它显示个人资料图片、用户名、电子邮件和 * 注销 * 按钮。下面是我的 LoginViewController 代码:
*** 仅供参考,代码仅显示了一个 FB 登录按钮、常规登录按钮和一个注册按钮的初始视图,并隐藏了个人资料图片视图、用户名和电子邮件以启动。登录后,我有相同的视图控制器,现在显示个人资料图片、用户名和电子邮件,隐藏*未*单击的登录按钮。
#import "LoginViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
NOLogin.layer.cornerRadius = 3;
[NOLogin.layer setShadowColor:[UIColor blackColor].CGColor];
[NOLogin.layer setShadowOpacity:0.1];
[NOLogin.layer setShadowRadius:0.2];
[NOLogin.layer setShadowOffset:CGSizeMake(0.0, 1.1)];
[NOLogin.layer setBorderColor:[UIColor blackColor].CGColor];
[NOLogin.layer setBorderWidth:0.1f];
self.loginButton.delegate = self;
[self toggleHiddenState:YES];
_signUp.hidden = NO;
NOLogin.hidden = NO;
self.lblLoginStatus.text = @"";
self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
// self.
}
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:NO];
[self toggleUnhiddenState:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabcontroller = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"TabController"];
[self presentModalViewController:tabcontroller animated: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"];
}
-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:YES];
_signUp.hidden = NO;
NOLogin.hidden = NO;
}
-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
NSLog(@"%@", [error localizedDescription]);
}
-(void)toggleHiddenState:(BOOL)shouldHide{
self.lblUsername.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
self.profilePicture.hidden = shouldHide;
self.begin.hidden = shouldHide;
self.loggedinwallpaper.hidden = shouldHide;
}
-(void)toggleUnhiddenState:(BOOL)shouldShow{
_signUp.hidden = YES;
NOLogin.hidden = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)unwindToLogin:(UIStoryboardSegue *)segue {
}
#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 {
[segue destinationTabBabController]
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
- (IBAction)j:(id)sender {
}*/
- (IBAction)enter:(id)sender forEvent:(UIEvent *)event {
}
@end
在您初始化要展示的 ViewController 之后,您现在可以访问它的属性(您提到的属性并为它们分配您想要的值)。
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:NO];
[self toggleUnhiddenState:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabcontroller = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"TabController"];
//Get the first controller that will be displayed (could be of a different index, depends on how you set it up)
UIViewController *firstController = [[((UITabBarController *)self.window.rootViewController) viewControllers] objectAtIndex:0];//Modify UIViewController to your View controller class name...
//Now set the properties of that controller to the info you need. I've added one, please continue with the others...
firstController.lblUsername = self.lblUsername;
//Finally, present the tabController.
[self presentModalViewController:tabcontroller animated:YES];
}
我正在尝试执行一些我知道很简单的事情,但我不确定语法。
首先,我让用户输入 Facebook 登录信息,让他们登录。然后我的代码提取他们的个人资料图片、用户名、电子邮件和 Facebook 按钮,并将其显示在 "LoginiewController" 中。 prof pic 是一个名为 profilePicture 的视图控制器,用户名为 lblUsername,电子邮件为 lblEmail, FB 按钮名为 loginButton。
ALL 我想做的是编写一些代码,将这 4 个值发送到 ProfileViewController,这不是 segue 的下一个视图控制器,以便它显示个人资料图片、用户名、电子邮件和 * 注销 * 按钮。下面是我的 LoginViewController 代码:
*** 仅供参考,代码仅显示了一个 FB 登录按钮、常规登录按钮和一个注册按钮的初始视图,并隐藏了个人资料图片视图、用户名和电子邮件以启动。登录后,我有相同的视图控制器,现在显示个人资料图片、用户名和电子邮件,隐藏*未*单击的登录按钮。
#import "LoginViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
NOLogin.layer.cornerRadius = 3;
[NOLogin.layer setShadowColor:[UIColor blackColor].CGColor];
[NOLogin.layer setShadowOpacity:0.1];
[NOLogin.layer setShadowRadius:0.2];
[NOLogin.layer setShadowOffset:CGSizeMake(0.0, 1.1)];
[NOLogin.layer setBorderColor:[UIColor blackColor].CGColor];
[NOLogin.layer setBorderWidth:0.1f];
self.loginButton.delegate = self;
[self toggleHiddenState:YES];
_signUp.hidden = NO;
NOLogin.hidden = NO;
self.lblLoginStatus.text = @"";
self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
// self.
}
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:NO];
[self toggleUnhiddenState:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabcontroller = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"TabController"];
[self presentModalViewController:tabcontroller animated: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"];
}
-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:YES];
_signUp.hidden = NO;
NOLogin.hidden = NO;
}
-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
NSLog(@"%@", [error localizedDescription]);
}
-(void)toggleHiddenState:(BOOL)shouldHide{
self.lblUsername.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
self.profilePicture.hidden = shouldHide;
self.begin.hidden = shouldHide;
self.loggedinwallpaper.hidden = shouldHide;
}
-(void)toggleUnhiddenState:(BOOL)shouldShow{
_signUp.hidden = YES;
NOLogin.hidden = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)unwindToLogin:(UIStoryboardSegue *)segue {
}
#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 {
[segue destinationTabBabController]
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
- (IBAction)j:(id)sender {
}*/
- (IBAction)enter:(id)sender forEvent:(UIEvent *)event {
}
@end
在您初始化要展示的 ViewController 之后,您现在可以访问它的属性(您提到的属性并为它们分配您想要的值)。
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:NO];
[self toggleUnhiddenState:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabcontroller = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"TabController"];
//Get the first controller that will be displayed (could be of a different index, depends on how you set it up)
UIViewController *firstController = [[((UITabBarController *)self.window.rootViewController) viewControllers] objectAtIndex:0];//Modify UIViewController to your View controller class name...
//Now set the properties of that controller to the info you need. I've added one, please continue with the others...
firstController.lblUsername = self.lblUsername;
//Finally, present the tabController.
[self presentModalViewController:tabcontroller animated:YES];
}