Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 选择“表视图控制器”单元格时,视图控制器将不显示_Ios_Swift_Xcode_Uistoryboard - Fatal编程技术网

Ios 选择“表视图控制器”单元格时,视图控制器将不显示

Ios 选择“表视图控制器”单元格时,视图控制器将不显示,ios,swift,xcode,uistoryboard,Ios,Swift,Xcode,Uistoryboard,我对Swift/Xcode比较陌生,我试图在选择按钮(添加按钮)或表格视图单元格(允许编辑)时,使视图控制器以不同的值显示。然而,在选择我的行时,我无法得到任何响应,包括我放入测试的打印语句,尽管当我将转换链接到按钮时,segue确实起作用。该代码与我之前编写的一个工作表视图单元格的代码相同,该单元格使当前表视图出现。这可能是故事板的问题吗 这是我的密码: override func numberOfSections(in tableView: UITableView) -> Int {

我对Swift/Xcode比较陌生,我试图在选择按钮(添加按钮)或表格视图单元格(允许编辑)时,使视图控制器以不同的值显示。然而,在选择我的行时,我无法得到任何响应,包括我放入测试的打印语句,尽管当我将转换链接到按钮时,segue确实起作用。该代码与我之前编写的一个工作表视图单元格的代码相同,该单元格使当前表视图出现。这可能是故事板的问题吗

这是我的密码:

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return items.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
    cell.textLabel?.text = items[indexPath.row].name
    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("Selected")
}

//Sends current receipt information to the AddItemViewController display when tapped
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "AddItemViewSegue" || segue.identifier == "EditItemViewSegue" {
        let destination = segue.destination as? AddItemViewController
        destination?.currentReceipt = currentReceipt
        let index = tableView.indexPathForSelectedRow?.row
        print("test")
        if segue.identifier == "AddItemViewSegue" {
            destination?.addMessage = "Add a New Item to Your Receipt"
            destination?.buttonMessage = "Add Item"
        }
        else {
            print("test1")
            destination?.addMessage = "Edit an Item in Your Receipt"
            destination?.buttonMessage = "Edit Item"
            destination?.currentItem = items[index!]
        }
    }
}
我也查看了这个论坛帖子,因为它和我的类似,但我无法应用任何建议的修复。

首先,didSelectRow方法是错误的。代码是Swift 2代码。正确的签名是

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { ...
难道你不想知道为什么编译器没有抱怨缺少
覆盖


不要从视图控制器将序列(为什么有两个?)从表视图单元格重新连接到目标控制器,并删除
didSelectRow

如果使用didSelectRow,则需要使用performsguewithidentifier您是否尝试为单元格设置代理高度?