You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode中Table View Cell手动(自动)Segue点击无响应求助

Hey there! Let's work through this segue issue step by step—it's super common when you're starting out with Xcode, so don't worry.

First: Clarify Automatic vs Manual Segues

It sounds like you might have mixed up how automatic and manual segues work, which is probably the root cause:

  • Automatic Segue: This is when you drag directly from your MealTableViewCell to the MealViewController in Storyboard. When set up correctly, tapping the cell will trigger the segue automatically, no extra code needed.
  • Manual Segue: This is when you drag from the MealTableViewController (not the cell) to the MealViewController. For this type, tapping the cell won't do anything unless you explicitly trigger the segue in code.

If you're using a manual segue, you're missing a critical step: implementing the tableView(_:didSelectRowAt:) method to fire the segue. Add this to your MealTableViewController:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // Trigger the manual segue with your identifier
    performSegue(withIdentifier: "ShowDetail", sender: tableView.cellForRow(at: indexPath))
}

Without this code, the manual segue has no way to know when to run—that's why your prepare(for:sender:) and shouldPerformSegue(withIdentifier:sender:) breakpoints aren't hitting.

Next: Double-Check Key Settings

Even if you have the right segue type, let's verify a few things:

  1. Segue Identifier: Open Storyboard, select your "ShowDetail" segue, and confirm the identifier in the Attributes Inspector matches exactly (Swift is case-sensitive, so "showDetail" won't work if your code uses "ShowDetail").
  2. Segue Source: For automatic segues, make sure the segue originates from the cell, not the view controller. For manual segues, it should originate from the view controller.
  3. Table View & Cell Interaction:
    • You already checked Table View's Selection is set to "Single Selection"—good, double-check it again just to be safe.
    • Ensure your MealTableViewController is set as the Table View's dataSource and delegate (check the Connections Inspector for the Table View; these connections are required for didSelectRowAt to fire).
    • If you added any custom subviews to your cell, make sure none of them have User Interaction Enabled unchecked (this can block tap events from reaching the cell).

Xcode Version Compatibility

Rest easy—Xcode 11.6 fully supports both automatic and manual segues. Your working "AddItem" segue proves that segues are functioning correctly in your project, so version isn't the issue here.

Quick Debug Test

To confirm if cell taps are being registered at all, add a print statement to didSelectRowAt:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print("Cell at row \(indexPath.row) was tapped!")
    performSegue(withIdentifier: "ShowDetail", sender: tableView.cellForRow(at: indexPath))
}

If you don't see this print when tapping a cell, the problem is with the Table View/cell's interaction setup, not the segue itself. In that case, recheck the dataSource/delegate connections and cell interaction settings.


内容的提问来源于stack exchange,提问作者Andrew Allen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 16:47:48