对不起,我对code & Swift是个新手。
无法发布图像,但我需要将我的自定义UITableViewController 7动态原型细胞链接到7个不同的UItableviewcontrollers。到目前为止,我尝试将单元分割到另一个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()
}
}和categories data.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!
}发布于 2015-03-15 18:26:53
也许可以张贴图片,这样我们就可以看到你为什么要走那条路线。
我想您希望表格视图的各个部分显示不同的内容?
我建议:
override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { }
根据区段和行号设置内容
发布于 2015-03-15 19:30:49
试试这个:
cellForRowAtIndexPath中,使用该行的类别获取正确的原型单元格:让categories = Categories作为Categories让CategoriesCell = categoryindexPath.row forIndexPath: indexPath)作为Categories
https://stackoverflow.com/questions/29059541
复制相似问题