您好,我以编程方式创建按钮并将按钮连接到另一个视图,但我遇到了 segue 问题
我应该对故事板使用prepareForSegue方法,但我不知道互联网上有一些示例,但当我使用该示例时我会收到错误,请你帮助我
提前致谢!
这是我的代码
创建按钮
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor colorWithRed: 201.0/255.0 green: 201.0/255.0 blue:201.0/255.0 alpha: 1.0];
button.tag = currentTag;
currentTag++;
[button.layer setBorderColor: [[UIColor blackColor] CGColor]];
[button.layer setBorderWidth: 1.0];
[button setTitle:[NSString stringWithFormat:@"%d",currentTag] forState:UIControlStateNormal];
button.frame = CGRectMake(80*x, 32*y, 80, 32);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonView addSubview: button];
按钮的操作
-(void)buttonPressed:(UIButton *)button
{
NSLog(@"button %u -- frame: %@", button.tag, NSStringFromCGRect(button.frame));
WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
[self.navigationController pushViewController:crtObj animated:YES];
[crtObj release];
}
准备继续
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"WeekView"]) {
// Get reference to the destination view controller
WeekView *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object]; //// I don't know what should I write instead of object
}}
error
编辑2:**** 我有一个警告:
直接从视图控制器启动的 Segue 必须具有与 -[UIViewController PerformSegueWithIdentifier:sender:] 一起使用的标识符
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"WeekView"]) {
// Get reference to the destination view controller
// WeekView *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
// [vc setMyObjectHere:object];
[segue.destinationViewController setTitle:@"WeekView"];
}}