我正在尝试链接弹出的UIAlertView中的一个按钮,以便它更改为另一个viewcontroller。基本上,取消已经有效,但是当单击Next时它没有,我不知道如何链接到另一个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 :(得分:0)
它正在工作......只需创建要呈现的viewcontroller对象而不是
UIViewController* newView = [[UIViewController alloc] init];
喜欢
SecondViewController * newView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
如果您使用的是xib。
或
SecondViewController * newView = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
如果你正在使用故事板(如果你想通过编码)。
然后写
[self presentViewController:newView animated:YES completion:nil];
线。