我使用 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;
}
有关我收到的警告,请参阅我的以下评论。