在我的第一個視圖控制器中,我有一個按下按鈕調用的函數。變量不在視圖控制器之間共享
func BuyButton(sender:UIButton) {
print("clicked cell is at row \(sender.tag)")
let indexPath = NSIndexPath(row: sender.tag, section: 0)
let currentCell = tableView.cellForRow(at: indexPath as IndexPath) as! CustomCell
let Storyboard = UIStoryboard(name: "Main", bundle: nil)
let PaymentController = Storyboard.instantiateViewController(withIdentifier: "PaymentViewController") as! PaymentViewController
print(currentCell.Test.text!) //prints fine here
PaymentController.RecordTitle = currentCell.Test.text!
performSegue(withIdentifier: "Buy", sender: self)
}
在我的付款視圖控制器我將變量定義爲
var RecordTitle = String()
在我看來沒我的付款視圖控制器的負載我嘗試打印RecordTitle並沒有什麼打印
print(RecordTitle)//Nothing prints in payment view controller
我究竟做錯了什麼?我已經嘗試了多種方法,但都沒有效果。
更接受「SWIFTY 「** var的方式RecordTitle = String()**是** var recordTitle =」「**。駱駝案例變量和可能的推斷類型。 – dfd