2014-09-04 53 views
0

我正试图链接我弹出的UIAlertView中的一个按钮,使其更改为另一个视图控制器。基本上,取消已经工作,但当下一个被点击它没有,我不知道如何链接到另一个视图控制器。请帮忙。xcode如何将UIAlertview动作链接到另一个viewcontroller?

#import "ViewController.h" 

@interface ViewController() <UIAlertViewDelegate> 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
- (IBAction)clickButton:(id)sender { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Test" message: @"Message" delegate: self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Redeem", nil]; 
    [alert show]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if(buttonIndex == 1){ //Next 
     UIViewController* newView = [[UIViewController alloc] init]; 
     [self presentViewController:newView animated:YES completion:nil]; 
    } 
    } 

@end 

回答

0

它的工作...只需创建视图 - 控制的对象,你想提出的,而不是

UIViewController* newView = [[UIViewController alloc] init]; 

SecondViewController * newView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

如果您使用的厦门国际银行。

或者

SecondViewController * newView = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; 

,如果你使用的是故事板(如果你想通过编码)。

,然后写

[self presentViewController:newView animated:YES completion:nil]; 

线。

+0

这里是项目文件,请告诉我我要改变什么。 https://www.dropbox.com/s/h5ye9jvxonyxxgd/StackOverflow%20Example.zip?dl=0 – 2014-09-04 05:44:15

+0

我没有那么多时间......再加上你必须自己学习...只是看任何演示“如何在ios中呈现视图控制器”。 – vivek 2014-09-04 05:47:57

+0

如果我的文章帮助你,然后接受我的答案。 – vivek 2014-09-04 05:48:40

相关问题