Reputation:
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"];
}
}
Upvotes: 20
Views: 26047
Reputation: 11257
Segues initiated directly from view controllers must have an identifier for use with -[UIViewController performSegueWithIdentifier:sender:]
This warning occurs when you drag a segue directly from a View Controller in Storyboard (aka, not from a button or any action control) and don't type in an Identifier (Name).
You have to give these ones a Identifier or else there's no way to call them programmatically... which is the only reason why you would link a segue like this.
In Xcode 8, you should be able to double click the warning to have the storyboard bring up the offending segue so that you can add a name to it.
Upvotes: 31
Reputation: 23053
This was solved my problem.
Go to Storyboard > Check for all Push or Pop relation segue.
Select each segue relationship > Check Attribute inspector properties > Storyboard Segue section
In that section give identifier for all segue.
Upvotes: 13
Reputation: 39
I had the same warning. You have to check every segue if it has an identifier as XCool said.
Xcool - I had this problem as well when looking back at an older project. I had to click on each storyboard segue and check if it's originating from a view controller. If it is, then I give it an identifier.
Also check your unwind segues! This solved the problem for me.
Upvotes: 3
Reputation:
In Xcode 5 I made this warning go away by naming not only the segues but the view controllers they lead to - each view controller needs a Storyboard ID. If you only name the segues this (misleading) warning will still appear.
Upvotes: 6