如何以编程方式将我的按钮连接到另一个视图控制器类
这是我的编程按钮的代码
UIBarButtonItem *yearButton= [[UIBarButtonItem alloc] initWithTitle:@"Year" style:UIBarButtonItemStyleBordered
target:self action:@selector(year:)];
-(void) year:(id)sender{
NSLog(@"Year button clicked");
//I don't know what should I write here to connect my button to UIViewController**
//when I added this line my process is terminated**
[self performSegueWithIdentifier:@"YearView" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString: @"YearView"]){
[segue.destinationViewController setTitle:@"YearView"];
}
}
在这里您可以在情节提要中看到我的视图:![在此处输入图像描述][1]
编辑: *当我使用此方法时,我的进程已终止*
-(void)year:(id)sender{
// [self performSegueWithIdentifier:@"YearView" sender:self];
NSLog(@"Year button clicked");
YearView *yearVC = [[YearView alloc] initWithNibName:@"YearView" bundle:nil];
[[self navigationController] pushViewController:yearVC animated:YES]; // [yearVC release];
}