本文介绍了Storyboard TableView 与 Segues 到多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在设计故事板时遇到了问题.我目前在应用商店中有一个使用 XIB 文件设计的应用.我在 UIViewController 上放置了一个 tableView - 而不是 tableViewController - 它为选定的每一行加载一个唯一的 viewController.

I am having an issue with designing a storyboard. I currently have an app in the app store that was designed with XIB files. I have a tableView placed on a UIViewController - not a tableViewController - that loads a unique viewController for each row that is selected.

我正在尝试将此概念转换为故事板.我做了以下

I am trying to convert this concept to a storyboard. I've done the following

  1. 在 Storyboard 中放置一个 UIViewController.

  1. Place a UIViewController in the Storyboard.

在 UIViewController 上放置一个 UITableView,以便我可以自定义表格视图.

Place a UITableView on the UIViewController so I can customize the table view.

我尝试从 UITableViewCell 连接到多个 ViewController,但不允许.

I tried making connections to multiple ViewControllers from the UITableViewCell and I am not allowed.

我尝试从 UIViewController 创建多个 segues - 我可以 - 但是当我点击单元格时,segues 不会被触发.我尝试使用 didSelectRowAtIndexPath: 和 prepareForSegue:

I tried creating multiple segues from the UIViewController - which I can - but when I click on the cells the segues are not fired. I tried using didSelectRowAtIndexPath: and prepareForSegue:

由于这不起作用,我尝试使用 UITableViewController 创建一个项目,然后从 UITableViewController 创建多个 segue.然后我命名每个 segue 并使用 didSelectRowAtIndexPath: 方法来测试选定的单元格并调用 performSegueWithIdentifier: 这不起作用.当我点击单元格时,我会随机加载不正确的 viewController.我在下面复制了一些代码和一些屏幕截图.

Since this did not work I tried creating a project with a UITableViewController and then created multiple segues from the UITableViewController. I then named each segue and used the didSelectRowAtIndexPath: method to test the selected cell and called performSegueWithIdentifier: and this did not work. As I clicked on cells I would get random loading of the incorrect viewController. I've copied a bit of my code and few screen shots below.

我想知道我是否明显遗漏了一些明显的东西,还是我必须为这种类型的项目恢复为 xib 格式?

I am wondering if I am blatantly missing something obvious or do I have to revert to a xib format for this type of project?

override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)
{
    if indexPath.row == 0
    {
        println("Segue1")
        self.performSegueWithIdentifier("Segue1", sender: self)
    }
    else if indexPath.row == 1
    {
        println("Segue2")
        self.performSegueWithIdentifier("Segue2", sender: self)
    }
    else if indexPath.row == 2
    {
        println("Segue3")
        self.performSegueWithIdentifier("Segue3", sender: self)
    }

}

保重,

乔恩

推荐答案

方法override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) 在取消选择项目时调用.

The methodoverride func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) is called when an item is deselected.

要在选择项目时调用方法,请将方法名称更改为 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

To call a method when an item is selected, change the method name to override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

这篇关于Storyboard TableView 与 Segues 到多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:35