Facebook 登录后无法推送到 PFQueryTableViewController
Posted
技术标签:
【中文标题】Facebook 登录后无法推送到 PFQueryTableViewController【英文标题】:Trouble Pushing to PFQueryTableViewController after Facebook Login 【发布时间】:2013-02-27 01:46:18 【问题描述】:我使用 Facebook 成功登录。登录视图是一个 UIViewController。我只能使用
访问 Parses 的登录功能@interface LoginViewController : UIViewController <PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate>
问题是,一旦我成功登录,我希望用户看到一个 PFQueryTableViewController。该应用程序全部基于列表,因此推送到此是有意义的。
我试过了:
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user
[self dismissViewControllerAnimated:YES completion:^
NSLog(@"Successfully logged in.");
MyPFQueryTableViewController *controller = [[MyPFQueryTableViewController alloc] init];
//Not sure what to do here...
];
最初我推送到 TableView。我已经删除了那个代码,坦率地说我不知道我是怎么做到的。
但发生的事情是我看到 UIViewController 片刻,然后 PFQueryTableViewController 出现了。
不仅如此,PFQueryTableViewController 没有显示导航栏,即使表格嵌入在导航控制器中。
这是我的 LoginViewController.m 的代码
#import "LoginViewController.h"
#import <Parse/Parse.h>
#import "MyPFQueryTableViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
// Custom initialization
return self;
- (void)viewDidLoad
[super viewDidLoad];
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsFacebook;
// Need to set the delegate to be this controller.
login.delegate = self;
login.signUpController.delegate = self; //signUpController is a property on the login view controller
[self presentModalViewController:login animated:NO];
// Do any additional setup after loading the view.
/*
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
UINavigationController *navigationController = segue.destinationViewController;
MyPFQueryTableViewController *controller = (MyPFQueryTableViewController *)
navigationController.topViewController;
- (void)viewDidAppear:(BOOL)animated
MyPFQueryTableViewController *controller =
[[MyPFQueryTableViewController alloc] initWithClassName:@"Lists"];
[self presentViewController:controller animated:NO completion:nil];
*/
//Four delegation methods below.
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user
[self dismissViewControllerAnimated:YES completion:^
NSLog(@"Successfully logged in.");
MyPFQueryTableViewController *controller = [[MyPFQueryTableViewController alloc] init];
//Not sure what to do here...
];
我想也许我需要使用 segue 方法,但我不太确定。
更新:
根据以下答案,我正在尝试通过 MyPFQueryTableViewController.m 文件中的 presentModalViewController 推送登录。
- (void)viewDidLoad
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsFacebook;
login.delegate = self;
login.signUpController.delegate = self;
[self presentModalViewController:login animated:NO];
//self.navigationItem.rightBarButtonItem = self.editButtonItem;
有关我收到的警告,请参阅我的以下评论。
【问题讨论】:
【参考方案1】:一种选择是将 PFQueryTableViewController 作为初始视图控制器,并在应用程序启动时以模态方式呈现 LoginViewController。这就是我在我的一个应用中使用 Parse 时所做的
【讨论】:
哦,这实际上可以工作......看一些代码会不会太麻烦?如果是这样,没什么大不了的。没想到! 我现在没有我的应用程序代码,但是如果您使用情节提要,请将 MyPFQueryTableViewController 设置为初始视图,否则在应用程序委托的应用程序中:应用程序 didFinishLaunchingWithOptions: 将其设置为rootViewController 然后在 MyPFQueryTableViewController 的 viewDidLoad 中初始化 loginViewController 并呈现它。 甜蜜。今晚我会试一试。在那之前我会一直打开它,如果它成功了,我会关闭它。 PFLoginViewController 不只是从 UIViewController“继承”吗?我想这就是我从没想过我能做到这一点的原因。 我有一个警告:“从不兼容的类型 'MyPFQueryTableViewController' 分配给 'id以上是关于Facebook 登录后无法推送到 PFQueryTableViewController的主要内容,如果未能解决你的问题,请参考以下文章