ios Segues 直接从故事板 xcode 中的视图控制器警告启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11135741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:53:20  来源:igfitidea点击:

Segues initiated directly from view controllers warning in storyboard xcode

iosobjective-cstoryboardsegueuistoryboardsegue

提问by Travis M.

Hi I have created button programmatically and I connected it to another view, but I got segue warning

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

that I should use prepareForSeguemethod 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

我应该使用prepareForSegue故事板的方法,但我不知道如何,互联网上有一些示例,但是当我使用该示例时出现错误,请您帮帮我

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 segueMY Warning

准备继续我的警告

Segues initiated directly from view controllers must have an identifier for use with -[UIViewController performSegueWithIdentifier:sender:]

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

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

回答by Travis M.

Segues initiated directly from view controllers must have an identifier for use with -[UIViewController performSegueWithIdentifier:sender:]

直接从视图控制器启动的 Segue 必须有一个标识符用于 -[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).

当您直接从 Storyboard 中的视图控制器(即,不是从按钮或任何操作控件)拖动 segue 并且不输入标识符(名称)时,会出现此警告。

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.

您必须给这些标识符一个标识符,否则就无法以编程方式调用它们……这是您将像这样链接 segue 的唯一原因。

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 8 中,您应该能够双击警告让故事板调出有问题的转场,以便您可以为其添加名称。

回答by Kampai

This was solved my problem.

这解决了我的问题。

Go to Storyboard > Check for all Push or Pop relation segue.

转到 Storyboard > 检查所有 Push 或 Pop 关系 segue。

Select each segue relationship > Check Attribute inspector properties > Storyboard Segue section

选择每个 segue 关系 > 检查属性检查器属性 > Storyboard Segue 部分

In that section give identifierfor all segue.

在该部分中为所有 segue提供标识符

enter image description here

在此处输入图片说明

回答by Adam Eberbach

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.

在 Xcode 5 中,我通过不仅命名 segue 还命名它们导致的视图控制器来消除此警告 - 每个视图控制器都需要一个 Storyboard ID。如果你只命名 segue 这个(误导)警告仍然会出现。

回答by manizzo

I had the same warning. You have to check every segue if it has an identifier as XCool said.

我有同样的警告。您必须检查每个 segue 是否有 XCool 所说的标识符。

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.

Xcool - 在回顾旧项目时,我也遇到了这个问题。我必须点击每个故事板 segue 并检查它是否来自视图控制器。如果是,那么我给它一个标识符。

Also check your unwind segues!This solved the problem for me.

还要检查您的放松转场!这为我解决了这个问题。