gpt4 book ai didi

naming-conventions - Storyboard Segue 标识符命名约定

转载 作者:行者123 更新时间:2023-12-03 06:50:05 24 4
gpt4 key购买 nike

我正在构建一个大型 Storyboard,我想知道是否有人提出了有用的 Segue 标识符的命名约定 .

看起来苹果只是在他们的例子中使用了“ShowX”,其中 X 是它显示的 View 的名称。到目前为止,我更喜欢使用“PushX”或“ModalX”来跟踪它是哪种类型的过渡。任何人有任何其他技巧或提示?

最佳答案

这个问题没有正确答案。这取决于口味。我减轻了可读性。不要羞于为您的 segue 标识符提供一个长名称;给出长而富有表现力的名字,因为 Objective-C 是一种非常冗长的语言,它利用我们编写非常易读的代码。

我已经搜索了一个官方 session ,但我找不到任何。这是Apple必须说的话:

You assign identifiers to your segues in Interface Builder. An identifier is a string that your application uses to distinguish one segue from another. For example, if you have a source view controller that can segue to two or more different destination view controllers, you would assign different identifiers to each segue so that the source view controller’s prepareForSegue:sender: method could tell them apart and prepare each segue appropriately.



来自 Ray Wenderlich's site 的另一句话:

Give the segue a unique Identifier. (It only has to be unique in the source scene; different scenes can use the same identifier.)



一种选择标识符名称的有趣方法(有关更多信息,请参见上面的链接):
  • 在您甚至在界面构建器中设置名称之前,首先编写验证 segue 标识符名称的代码。我说的是这个代码:if ([segue.identifier isEqualToString:@"SegueIdentifierName"])
  • 构建和运行!暂时不要在 Interface Builder 中填写标识符名称。你这样做是因为你可能有来自一个 View Controller 的多个传出 segue,你需要能够区分它们。如果在您运行并触发您正在处理的 segue 时没有任何 react ,那么您的 segue 名称标识符是唯一的并且可以很好地使用。相反,如果代码执行了您不想要的 segue,那么您的 sague 名称标识符就会发生冲突。
  • 解决冲突 - 如果有的话。
  • 在 Interface Builder 中填写 segue 标识符并测试它是否满足您的要求。

  • 我喜欢这个,因为它就像 TDD 方法:编写一个失败的测试,编写一些代码来通过失败的测试,重构,重复。

    关于naming-conventions - Storyboard Segue 标识符命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15370133/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com