قالب وردپرس درنا توس
Home / IOS Development / The variable is not set (or reset) outside the function? : iOS Programming

The variable is not set (or reset) outside the function? : iOS Programming



So I have a class:

  import UIKit

class attributeSelect: UITableViewController {
was selectedAttribute = "FOO"
}

And then I have a table that is populated with different values ​​from matrices, and which everything works fine and dandy. But as part of that I have this:

  override func tableView (_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedAttribute = attributes [indexPath.item]
print (selectedAttribute)
}

… which also works. Assuming the selected attribute is BAR, it prints BAR.

But the problem is that the variable does not remain set. The table cell calls a relaxing segment, and the original display controller requests the value of the selected attribute – which is read as "FOO."

I don't understand why this happens.


Source link