由于某种原因,我无法将值发送到我的AddParticipant视图。
这里的数据是" ValuetoPass"在segue之后:" LAbelText"
ValuetoPass = GXEuoAkhjP LabelText =
segue的TableView代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//CODE TO BE RUN ON CELL TOUCH
let indexPath = tableView.indexPathForSelectedRow!;
let currentCell = tableView.cellForRowAtIndexPath(indexPath) as UITableViewCell!;
let valueToPass = self.participantId[indexPath.row] as String
print("ValuetoPass = ",valueToPass)
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "editParticipant") {
let viewController = segue.destinationViewController as! AddViewController
viewController.LabelText = valueToPass; }
}
}
AddViewController的代码:
@IBOutlet weak var firstnameTF: UITextField!
@IBOutlet weak var lastnameTF: UITextField!
@IBOutlet weak var gradeTF: UITextField!
@IBOutlet weak var teacherTF: UITextField!
@IBOutlet weak var emailTF: UITextField!
@IBOutlet weak var phoneTF: UITextField!
@IBOutlet weak var transportationTF: UITextField!
@IBOutlet weak var userSchoolTF: UITextField!
var LabelText = String()
@IBOutlet weak var qrCode: UIImageView!
@IBOutlet weak var userPicture: UIImageView!
override func viewDidAppear(animated: Bool) {
}
override func viewDidLoad() {
super.viewDidLoad()
print("LabelText = ", LabelText)
let currentUser = PFUser.currentUser()
currentUser!.refreshInBackgroundWithBlock { (object, error) -> Void in
// print("Refreshed")
currentUser!.fetchIfNeededInBackgroundWithBlock { (result, error) -> Void in
self.userSchoolTF.text = currentUser!.objectForKey("school") as? String
}
}
所以我在发送之前有数据,但在segue之后显示为nil
答案 0 :(得分:0)
Swift是否有NSString对象?或者String是一回事吗?
在目标c中,分配给对象指针正在创建对前一个对象的引用。当你使它变弱时,它不会添加到引用计数,所以如果你解除分配原始指针,你就可以释放它们。强意味着它确实添加了引用计数,因此释放第一个不会实际释放对象。
如果String和NSString是两个不同的东西,请尝试改为使用NSString类型,并查看是否保留了它。
我在Obj-C工作,而不是Swift工作,而且我不确定两者之间的细微差别。
答案 1 :(得分:0)
我想你在Storyboard中创建了segue,对吗? 将prepareForSegue函数放在tableView函数之外。另外prepareForSegue应该覆盖。尝试使用以下代码
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if( segue.identifier == "editParticipant" ){
if let destinationVC = segue.destinationViewController as? AddViewController {
destinationVC.LabelText = valueToPass
}
}
}