У меня проблема с моим кодом, я думаю, что проблемы появились после того, как я изменил синтаксис на новую быструю версию.Значение дополнительного типа 'NSIndexPath?' не разворачивается; вы хотели использовать '!' или '?'?
import UIKit
class FirstTableViewController: UITableViewController {
var FirstTableArray = [String]()
var passThisArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// This array will display on your tableviewcell.
FirstTableArray = [lib1]
//You can pass element of this array
passThisArray = ["1. Fi "]
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return FirstTableArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
Cell.textLabel?.text = passThisArray[(indexPath as NSIndexPath).row]
return Cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "detailView") {
let vc = segue.destination as! ViewController
//Get the Index of selected Cell
let indexPath : IndexPath = self.tableView.indexPathForSelectedRow!
//assign string to next view controller instance from selected cell.
vc.FirstString = FirstTableArray[(indexPath as NSIndexPath).row]
}
}
}
На этой линии он дает мне 2 ошибки: '? NSIndexPath'
let indexPath : IndexPath = self.tableView.indexPathForSelectedRow!
1.Value дополнительного типа не разворачивается; вы хотели использовать '!' или '?'? 2. Неправильное использование '()' для вызова значения нефункционного типа 'NSIndexPath?'
Thankyou.
большое спасибо, да охранник утверждение было решением. –
Также большое спасибо за рекомендации, да, я знаю о camelCase, но в этом случае я думаю, что я следовал учебнику. –
@BeSar Нет проблем, рад, что теперь он работает – CodeBender