cod*_*ule 0 ios segue swift swift3
我需要将此字符串值传递给另一个viewController.由于某种原因,我得到一个sigabrt错误.任何人都可以指出我做错了什么?
需要将userIdentityString值传递给userCellTapped viewcontroller
class GeneralChatroom: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate {
//Get Data of current cell that has been tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
//Eliminate highlight after cell is tapped
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let userIdentityString : String = generalRoomDataArr[indexPath.row].cellUserId
let destinationUID = userCellTapped()
destinationUID.programVar = userIdentityString
destinationUID.performSegue(withIdentifier: "profileTapped", sender: self)
}
}
import UIKit
class userCellTapped: UIViewController {
var programVar : String!
override func viewDidLoad() {
super.viewDidLoad()
print("testbles", programVar)
}
}
Run Code Online (Sandbox Code Playgroud)
正确设置目标视图控制器变量的方法是prepare(for segue ...)
在您的ViewController
类中实现:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "profileTapped" {
if let destination = segue.destination as? MyDestinationViewControllerType {
destination.myVariable = myClassLevelVariable
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1147 次 |
最近记录: |