如何在点击按钮时立即打开viewcontroller

时间:2012-09-07 07:16:05

标签: iphone

我正在为iPhone开发一个e-com应用程序,我需要在用户点击即将到来的视图的按钮时立即打开视图,数据从服务器加载大图像,加载我正在使用背景的图像线程。

谢谢

3 个答案:

答案 0 :(得分:5)

简单来说,就是如何创建UIViewController并在IBAction内展示它。

- (IBAction)goToNextView:(id)sender
    {
     //if you are using xibs use this line
        UIViewController *controller = [[UIViewController alloc] initWithNibName:@"myXib" bundle:[NSBundle mainBundle]];
    //if you are using storyboards use this line
        UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"myViewControllersID"];

    //to present the controller modally use this
        [self presentViewController:controller animated:NO completion:nil];
    //or if you are pushing to this controller using a navigation controller use this
        [self.navigationController pushViewController:controller animated:NO];
    }

请务必传递动画NO,以便立即显示视图。

答案 1 :(得分:0)

您可以使用模态视图控制器

- (IBAction)showController:(id)sender {
    SampleViewController *sampleView = [[SampleViewController alloc] init];
    [self presentModalViewController:sampleView animated:YES];
}

这是教程http://timneill.net/2010/09/modal-view-controller-example-part-1/

答案 2 :(得分:0)

您需要创建一个按钮然后添加其操作,如

-(IBAction)ButtonAction:(id)sender{

CalController *calculateView=[[CalController alloc] initWithNibName:@"CalController" bundle:nil];
[self.navigationController presentModalViewController:calculateView animated:NO];  

}