在故事板xcode中直接从视图控制器警告启动的Segues [英] Segues initiated directly from view controllers warning in storyboard xcode

查看:279
本文介绍了在故事板xcode中直接从视图控制器警告启动的Segues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我已经以编程方式创建了按钮并将其连接到另一个视图,但我收到了segue警告



我应该使用 prepareForSegue 故事板的方法,但我不知道怎么样,互联网上有一些样本,但是当我使用那个样本时出现错误,请你帮帮我



这是我的代码



创建按钮

  UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.backgroundColor = [UIColor colorWithRed:201.0 / 255.0绿色:201.0 / 255.0蓝色: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 *)按钮
{
NSLog(@按钮%u - frame:%@,按钮。 tag,NSStringFromCGRect(button.frame));
[self performSegueWithIdentifier:@WeekViewsender:self];
}

准备segue 我的警告



直接从视图控制器启动的分段必须具有可用于的标识符 - [UIViewController performSegueWithIdentifier:sender:]

   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
if([[ segue identifier] isEqualToString:@WeekView]){
[segue.destinationViewController setTitle:@WeekView];
}
}


解决方案

直接从视图控制器启动的Segues必须具有一个标识符,用于 - [UIViewController performSegueWithIdentifier:sender:]



当您直接从Storyboard中的View Controller拖动se​​gue时(而不是从按钮或任何操作控件中)并且不键入标识符(名称)时会出现此警告。



你必须给这些人一个标识符,否则无法以编程方式调用它们......这就是为什么要像这样链接一个segue的唯一原因。 / p>

在Xcode 8中,您应该能够双击警告,让故事板显示违规的segue,以便您可以为其添加名称。


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"];
    }
}

解决方案

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.

这篇关于在故事板xcode中直接从视图控制器警告启动的Segues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆