我是Swift新手(我使用2.0),并没有任何编程经验。所以,我是新手)试图做一些相当简单的事情。链接一个UITableViewCell
点击呼叫不同的ViewController
。这就像用户点击单元车并打开新的ViewController
。链接一个单元格来调用不同的ViewController
我已经创建了ViewControllers (storyboard A,B,C,D,E)
。 我如何连接?如果我正确理解我应该使用didSelectRowAtIndexPath
。我曾问过
代码:
import UIKit
class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let list = ["Cars", "Fruits", "Foods", "Toys"]
let listdesc = ["Toyota", "Apple", "Meat", "Fallout 4"]
let identities = ["A", "B", "C", "D"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return list.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier: String = "cell"
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: cellIdentifier)
cell.textLabel?.text = list[indexPath.row]
cell.detailTextLabel?.text = listdesc[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
的,他应该设置'stoaryboard identifier'!你应该在回答中提到! – Lion
是的..他必须设置标识符... –
谢谢大家,我真的很感激。 as有2个严重错误! A和! B - >使用未声明的类型“A”和“B”。请检查我的故事板 - https://postimg.org/image/altu24893/ – JonnyA