ACR*_*ACR 1 uitableview ios swift
我正在创建一个应用程序,我有一个用户添加数据的UITableView,我希望用户能够点击单元格并查看有关他们选择的单元格的更多详细信息.我从cell到我的cellDetailController设置了一个segue,稍后我将添加他们选择的单元格的所有细节.当我运行应用程序并尝试点击要离开的单元格时,它只选择单元格并且没有任何反应.我在这做错了什么?这是我的故事板设置:
(我无法上传图片,所以这里有链接) http://tinypic.com/r/2ivcwsj/8
继承我连接到tableView的类的代码:
import UIKit
typealias eventTuple = (name: String, date: String)
var eventList : [eventTuple] = []
class TableViewController: UIViewController, UITableViewDelegate {
@IBOutlet weak var eventTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
eventTable.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return eventList.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
cell.textLabel?.text = eventList[indexPath.row].name
cell.detailTextLabel?.text = eventList[indexPath.row].date
return cell
}
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "showDetailSegue") {
}
}
}
Run Code Online (Sandbox Code Playgroud)
从tableViewController(viewController顶部的黄色图标)拖动segue,而不是从tableCell拖动.然后给该segue一个标识符.
didSelectRowAtIndexPath通过这里覆盖并执行segueperformSegueWithIdentifier()
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// pass any object as parameter, i.e. the tapped row
performSegueWithIdentifier("showDetailSegue", sender: indexPath.row)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3814 次 |
| 最近记录: |