ios - Swift - 执行 Segue

标签 ios swift self

if (view.annotation.title as String!) == "Helgoland " {
  currentLong = 7.889021
  currentLat = 54.180210 
  url = "google.com"

  let alertController: UIAlertController = UIAlertController(title: "Change Map Type", message: nil, preferredStyle: UIAlertControllerStyle.Alert)
  let cancelAction: UIAlertAction = UIAlertAction(title: "Back", style: UIAlertActionStyle.Cancel, handler: nil)
  let button1action: UIAlertAction = UIAlertAction(title: "Product Page", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in
    performSegueWithIdentifier("showShop", sender: self)
  })
  let button2action: UIAlertAction = UIAlertAction(title: "Video", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in
    youtubeVideoID = "XX"
    UIApplication.sharedApplication().openURL(NSURL(string: "http://www.youtube.com/watch?v=\(youtubeVideoID)"))
  })
  alertController.addAction(cancelAction)
  alertController.addAction(button1action)
  alertController.addAction(button2action)
  self.presentViewController(alertController, animated: true, completion: nil)
}

我总是出错

"Implicit use of 'self' in closure; use 'self.' to make capture semantic explicit"

但是如果我设置self.view,它也会失败。

最佳答案

您需要显式使用 self :

self.performSegueWithIdentifier("showShop", sender: self)

对于 Swift 3(感谢@KingChintz):

self.performSegue(withIdentifier: "showShop", 发件人: self)

关于ios - Swift - 执行 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26039672/

相关文章:

ios - iOS 7 中的核心蓝牙崩溃

ios - HTTP请求成功后如何在TableView中存值显示

ios - 如何使用 NSAttributedString 在 Swift 中将图像添加为文本附件?

python-2.7 - Python 2.7 : Self works as positional but not as keyword argument

python - 如何在 Python 中避免显式 'self'?

Javascript 使用显式的 self/window 对象来提高性能

ios - 识别谁在 iOS 中执行了手势

iPhone 5 屏幕截图未显示在 iPhone 5 App Store 上

ios - 有什么方法可以让 "Validate Project Settings"警告在 Xcode 4.3/4.3.1 中消失?

swift - 快速查询私有(private)数据库以获取用户详细信息