Hi I have created button programmatically and I connected it to another view, but I got segue warning
that I should use prepareForSegue
method for storyboard but I don't know how, there are some sample on Internet but I get an error when I used that sample, would you please help me
here is my code
Creating Button
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];
Action for button
-(void)buttonPressed:(UIButton *)button
{
NSLog(@"button %u -- frame: %@", button.tag, NSStringFromCGRect(button.frame));
[self performSegueWithIdentifier:@"WeekView" sender:self];
}
Prepare for segue MY Warning
Segues initiated directly from view controllers must have an identifier for use with -[UIViewController performSegueWithIdentifier:sender:]
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"WeekView"]) {
[segue.destinationViewController setTitle:@"WeekView"];
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…