简体   繁体   中英

Passing data from tableview cell to View Controller Swift 2.1

变量“sendTitle”无法访问

Anyone know why can't I access the variable 'sendTitle' in prepareForSegue from didSelectRowAtIndexPath? I saw some of the tutorials, they are doing the same thing with me, I've no idea why mine got error. --What I'm doing now is passing value from tableView cell to another view controller.

I'm using Xcode 7 Swift 2.1

Because it is declared privately in your didSelectRowAtIndexPath method. It won't be accessible outside of those function. if you want to access it from another function, declare it as global variable in your view controller.

you have to declare sendTitle inside your class to make it visible to all methods. Something like follows.

import UIKit

class viewController: UITableViewController {
   var sendTitle:String = ""

   override func viewDidLoad() {
       super.viewDidLoad()
   }

   //table view delegate methods 
   // just use sendTitle = cell.lblTitle.text!

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM