【问题标题】:Trying to switch views using a button only in a specific case仅在特定情况下尝试使用按钮切换视图
【发布时间】:2012-07-10 21:34:59
【问题描述】:

使用 Parse 框架,我试图让用户登录到应用程序,如果在用户按下登录按钮时登录有效,我希望改变视图。在这种特定情况下,如果(!错误)我希望切换视图。假设第二个视图被称为 PostingViewController,我怎样才能使它工作?

-(IBAction)signUpButton:(id)sender
{
    NSString *userInput = usernameInputField.text;
    NSString *userPassword = passwordInputField.text;
    PFUser *user = [PFUser user];
    user.username = userInput;
    user.password = userPassword;
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if(!error){ 

        }
        else{
            NSLog(@"there was a problem");
        }
    }];
}

【问题讨论】:

    标签: iphone xcode uiview uiviewcontroller uibutton


    【解决方案1】:

    只需创建一个 PostingViewController 对象并将其推送到当前的 navigationController

    类似的东西可能会有所帮助......

    PostingViewController *vc = [[PostingViewController alloc] initWithNibName:@"your_nib_name" andBundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:vc withAnimation:YES];
    [vc release];
    

    【讨论】:

    • 这似乎可行,但是当我在 if 语句中使用该代码时,我得到“'PostingViewController' 没有可见界面”和“UINavigationController 没有可见界面声明选择器 pushViewController:withAnimation”
    • 修复了 pushViewController:withAnimation 的错误,所以我必须感谢你:D。但现在我没有接口声明选择器,initWithNibNameAndBundle
    • [[PostingViewController alloc] initWithNibName:@"your_nib_name" bundle:[NSBundle mainBundle]];试试这个...
    • 没有错误,但是即使满足条件并且第二个视图的视图控制器称为 PostingViewController 并连接到界面生成器中的第二个视图,视图似乎也没有改变。跨度>
    • R 你确定你初始化了navigationController 以在其中堆叠你的viewcontrollers?
    猜你喜欢
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2023-01-13
    相关资源
    最近更新 更多