【发布时间】:2015-03-09 08:06:13
【问题描述】:
目前我有一个包含大学列表的表格视图。在点击其中之一后,我想显示有关这些大学的信息。我的表格视图单元格有样式:副标题。
我的tableview数据源是:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return schools.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("SchoolCell", forIndexPath: indexPath)
as UITableViewCell
let school = schools[indexPath.row] as Schools
cell.textLabel?.text = school.university
cell.detailTextLabel?.text = school.name
return cell
}
schools.swift 页面:
class Schools: NSObject {
var university: String
var name: String
init(university: String, name: String) {
self.university = university
self.name = name
super.init()
}
}
示例数据页:
let schoolsData = [ Schools(university: "Aberdeen", name: "School of Medicine")
//and so on for each university
我已经尝试了几个小时来使用 segues 链接这些页面。我已经通过 ctrl-click 拖动在情节提要上创建了 tableviewcell 和视图控制器之间的链接,但是我的 SchoolsViewTableController(表格视图)和 SchoolViewController 上的代码部分(为 segue 做准备)卡住了。
我希望详细信息页面显示“大学”(例如 Aberdeen)作为标题。
任何帮助将不胜感激 - 我对 swift 比较陌生,所以请理解我的经验不足!
谢谢
埃德
【问题讨论】:
标签: ios uitableview swift uiviewcontroller segue