gpt4 book ai didi

ios - UITableViewCell Segue 不工作

转载 作者:搜寻专家 更新时间:2023-11-01 05:54:02 25 4
gpt4 key购买 nike

我正在制作一个应用程序,其中有一个 UITableView,用户可以向其添加数据,我希望用户能够点击单元格并查看有关他们选择的单元格的更多详细信息。我设置了一个从单元格到我的 cellDetailController 的 segue,稍后我将在其中添加他们选择的单元格的所有详细信息。当我运行应用程序并尝试点击单元格进行 segue 时,它​​只是选择了单元格而没有任何反应。我在这里做错了什么?这是我的 Storyboard设置:

(我还不能上传图片所以这里是一个链接) 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") {

}
}
}

最佳答案

从 tableViewController(viewController 顶部的黄色图标)拖动 segue,而不是从 tableCell。然后给那个 segue 一个标识符。

覆盖 didSelectRowAtIndexPath 并通过 performSegueWithIdentifier() 在此处执行转场

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// pass any object as parameter, i.e. the tapped row
performSegueWithIdentifier("showDetailSegue", sender: indexPath.row)
}

关于ios - UITableViewCell Segue 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30820580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com