我遇到的问题是“发现”'无法找到segue的导航控制器'SignUpSegue'。推送segues只能在源控制器由UINavigationController实例管理时使用。“
我是iOS开发的新手,但是我已经完成了对这个问题的研究,其中一个常见的是嵌入到导航控制器中。我有一个初始视图控制器,登录页面,嵌入在里面一个导航控制器,还有一个按钮,该按钮会被推送到一个注册页面。当用户登录时,我通过注销来测试它,我的目标是返回登录页面。当用户注销并且登录页面完美显示时,我以模态方式显示登录页面。我可以再次登录,但如果我碰巧按下注册,它会冒犯并显示错误。请注意,注册页面通常有效,这就是为什么我很好奇它在注销后以模态方式发出警报。 segue都标题正确且连接有一个segue连接登录页面和注册页面以及一个segue将登出页面连接到登录页面。
一个附带问题,当我在注销后以模态方式显示登录页面时,我的destinationviewcontroller应该是登录视图或嵌入的导航控制器。 我非常感谢任何帮助,如果需要更多信息,我很乐意添加它。
这是登录页面的相关代码,logInViewController
// 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.
if([segue.identifier isEqualToString:@"SignInSegue"]){
HomeTab *logIn=[segue destinationViewController];
}
if([segue.identifier isEqualToString:@"SignUpSegue"]){
SignUpView *signUp=[segue destinationViewController];
}
}
- (IBAction)logInUser:(id)sender {
NSLog(@"Log In Attempted");
if([self fieldsEmpty]){
UIAlertView *signIn=[[UIAlertView alloc]initWithTitle:@"Empty Field(s)" message:@"Please make sure all fields are filled out" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[signIn show];
}
else{
[PFUser logInWithUsernameInBackground:UserName.text password:Password.text block:^(PFUser *user, NSError *error)
{
/*Successful sign in, go to home page*/
if(!error){
[self performSegueWithIdentifier:@"SignInSegue" sender:sender];
}
else{
UIAlertView *signIn=[[UIAlertView alloc]initWithTitle:@"Fail" message:@"Your username and password failed to match.\nPlease try again" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[signIn show];
}
}];
}
}
- (IBAction)signUpUser:(id)sender {
[self performSegueWithIdentifier:@"SignUpSegue" sender:sender];
}
以下是在其他视图控制器(Settings.m)上注销时的相关代码
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if([segue.identifier isEqualToString:@"logOutSegue"]){
LogInViewController *logIn=[segue destinationViewController];
}
}
- (IBAction)logOutCurrentUser:(id)sender {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Are You Sure?" message:@"If you would like to log out press continue, if not press cancel" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:@"Cancel", nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0){
[PFUser logOut];
[self performSegueWithIdentifier:@"logOutSegue" sender:self];
}
if(buttonIndex==1){
return;
}
}