gpt4 book ai didi

ios - 在 IBAction 之前调用 PrepareforSegue

转载 作者:行者123 更新时间:2023-11-28 13:14:29 27 4
gpt4 key购买 nike

我正在尝试在变量中传递一个值,以便在我点击它时在自定义单元格中获取 UIButton 的索引路径,并使用 prepareForSegue 将此值传递给另一个 View Controller :

var row2 = Int() 

@IBAction func Teste(sender: AnyObject) {
var btnPos: CGPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
var indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(btnPos)!
var row2 = Int(indexPath.row)
self.performSegueWithIdentifier("commentsIdentifier", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {


if (segue.identifier == "detailIdentifier") {
let detailScene = segue.destinationViewController as DetailViewController
// Pass the selected object to the destination view controller.
if let indexPath = self.tableView.indexPathForSelectedRow() {
let row = Int(indexPath.row)
detailScene.currentObject = objects[row] as? PFObject

}


} else if (segue.identifier == "commentsIdentifier") {
let commentScene = segue.destinationViewController as TesteButtonViewController
println(row2)

}

但是,当我在 prepareforsegue 中打印 row2 时,我看不到该值,我认为这是因为在 IBAction 之前调用了 prepareforSegue,请问我该如何解决这个问题?

最佳答案

你的 IBActionprepareForSegue 之前被调用,你的错误是其他原因。 只需更改行:

var row2 = Int(indexPath.row)

row2 = Int(indexPath.row)

目前正在发生的事情是,您在 Teste 中创建了一个具有函数作用域的局部变量,它隐藏了与您的类同名的变量。

关于ios - 在 IBAction 之前调用 PrepareforSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29593622/

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