UITableViewCell Segue 不工作 [英] UITableViewCell Segue not Working

查看:20
本文介绍了UITableViewCell Segue 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm making an app where I have a UITableView that the user adds data to, and I want the user to be able to tap on the cell and see more details about the cell they chose. I set up a segue from the cell to my cellDetailController where I will later add all the details of the cell they chose. When I run the app and try to tap on the cell to segue, it just selects the cell and nothing happens. What am I doing wrong here? Here is my storyboard set up:

(我还不能上传图片,所以这里有一个链接)http://tinypic.com/r/2ivcwsj/8

(I cant upload pictures yet so here's a link) http://tinypic.com/r/2ivcwsj/8

这是连接到我的 tableView 的类的代码:

Heres the code for my the class connected to my 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 顶部的黄色图标)而不是从 tableCell 拖动 segue.然后给那个 segue 一个标识符.

Drag the segue from the tableViewController (the yellow icon on the top of the viewController), not from the tableCell. Then give that segue an identifier.

覆盖 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)
}

这篇关于UITableViewCell Segue 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆