Swift:为什么 "performSegueWithIdentifier"会发生两次?

标签 swift uibutton segue

在我的应用程序中,我有以下 Storyboard片段:

enter image description here

从粉红色按钮,我在右侧的 UIViewController 中添加了一个名为“toFishPic”的显示转场。这是链接到粉红色按钮的快速代码:

@IBAction func toFishPhoto(sender: UIButton) {

    dispatch_async(dispatch_get_main_queue()) {
        self.performSegueWithIdentifier("toFishPic", sender: self)
    }
}

我不知道为什么,但是当点击粉红色按钮时,右侧的 UIViewConroller(带有大 UIImageView 的那个)被加载了两次,就好像它后面有一个相同的一样。为什么会这样?

最佳答案

我认为您将粉红色按钮直接链接到 PhotoViewController,而不是将 ActionFishViewController 链接到 PhotoViewController。如果您要使用 performSegueWithIdentifier,请不要直接链接并在 Controller 之间重新连接。

尽量不要调用 self.performSegueWithIdentifier("toFishPic", sender: self) (//) 并检查是否可以推送到 PhotoViewController。如果它有效意味着您将按钮直接链接到 PhotoViewController。

关于Swift:为什么 "performSegueWithIdentifier"会发生两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33898813/

相关文章:

swift - 开关语句 : converting from if-statement to switch statement in swift

ios - 带有图像的 MKPinAnnotationView 内的 UIButton

ios - Swift 3.0 标签空白(零值?)

ios - 使用 CATransition 的自定义 Segue 不工作

swift - 快速覆盖函数更新问题

ios - 缩放 SpriteKit 游戏

ios - 在背景中使用与主要 UIImage 颜色相同的颜色覆盖 UIView

ios - 突出显示 UIButton 出现不必要的延迟

iphone - 工具:创建 UIButton 时内存泄漏

indexing - 获取 UITableView 中选定附件按钮的 IndexPath