如何将动态原型单元链接到不同的UITableViewController?

如何将动态原型单元链接到不同的UITableViewController?,uitableview,swift,dynamic,prototype,cell,Uitableview,Swift,Dynamic,Prototype,Cell,对不起,我是新来的代码&斯威夫特 无法发布图像,但我需要将自定义UITableViewController 7动态原型单元链接到7个不同的UITableViewController。到目前为止,我试图将单元格分割到另一个UITableViewController,但其余单元格也链接到同一个位置。假设如果要将快餐类别链接到UITableViewController中的快餐店列表,则其他类别也会链接到同一UITableViewController 我不太清楚该怎么办 我的主控制器代码如下: clas

对不起,我是新来的代码&斯威夫特

无法发布图像,但我需要将自定义UITableViewController 7动态原型单元链接到7个不同的UITableViewController。到目前为止,我试图将单元格分割到另一个UITableViewController,但其余单元格也链接到同一个位置。假设如果要将快餐类别链接到UITableViewController中的快餐店列表,则其他类别也会链接到同一UITableViewController

我不太清楚该怎么办

我的主控制器代码如下:

class CategoriesTableViewController: UITableViewController {

    var category: [Categories] = categoriesData

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

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

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

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCell {
            let cell = tableView.dequeueReusableCellWithIdentifier("CategoriesCell", forIndexPath: indexPath)as CategoriesCell

                let categories = category[indexPath.row] as Categories
                cell.textLabel?.text = categories.category
                if let categoryLabel = cell.viewWithTag(100) as? UILabel {
                    categoryLabel.text = categories.category
                }
                return cell
            }
这是我的
categories.swift
文件:

class Categories: NSObject {
    var category: String
    init(category: String) {
        self.category = category
        super.init()
    }
}
类别数据。swift

let categoriesData = [Categories(category:"Restaurants/Cafe"), Categories(category:"Fine Dining"), Categories(category:"Catering"),Categories(category:"Buffet"), Categories(category:"Food Court/Hawker Centre"), Categories(category:"Fast Food"), Categories(category:"Others")]

my categories cell.swift shows the following:

class CategoriesCell: UITableViewCell {

    @IBOutlet weak var nameLabel: UILabel!
}

也许你可以贴些照片,让我们看看你为什么要走这条路

我想您希望tableview的各个部分显示不同的内容

我建议:

  • 将表视图拆分为所需的节数(每个节可以有给定数量的行)

  • 创建一个UITableViewController类

  • 在你的

    重写func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{ }

  • 根据节号和行号设置内容

    尝试以下操作:

  • 创建7个不同的原型单元
  • 更改每个原型单元的重用标识符以匹配其中一个类别
  • 使用segue将每个原型单元链接到不同的ViewController
  • cellforrowatinexpath
    中,使用该行的类别获取正确的原型单元格:

    let categories = category[indexPath.row] as Categories
    let cell = tableView.dequeueReusableCellWithIdentifier(categories.category, forIndexPath: indexPath) as CategoriesCell
    

  • 无法发布图像,因为我的声誉。。哈哈。我把我的问题编辑得更详细了。只要把它们放在dropbox或其他地方,并提供一个链接OK,我想我知道你想要什么。您不需要7个不同的UITableViewController。我可以进入你的项目吗?我会告诉你你想要什么现在创建7个原型,但我不确定如何写我的返回单元格。如何为7个单元格编写返回单元格,以及如何为行数部分编写返回单元格?