gpt4 book ai didi

xcode - 带有原型(prototype)单元格的 tableView.insertRowsAtIndexPaths

转载 作者:行者123 更新时间:2023-11-30 14:01:44 25 4
gpt4 key购买 nike

我正在尝试在我的 tableView 中插入原型(prototype)单元格之一。我定义了两个原型(prototype)单元并给了它们唯一的标识符,但我无法设法使用特定标识符插入它们。没有带有标识符的tableView.insertRowsAtIndexPaths这样的函数。

大家有什么想法吗?

最佳答案

您可以使用 cellForRowAtIndexPath 并在函数内部,您可以对原型(prototype)单元进行出队。这是一个例子

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//you can also have if condition here to choose between ur prototype cells
let cell = tableView.dequeueReusableCellWithIdentifier("unique id_1", forIndexPath: indexPath) as! UITableViewCell

// Configure the cell...

return cell
}

这是更常见的方法

//In parent class
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "MainCatSelectedSegue" {
if let tvc = segue.destinationViewController as? YourTableViewControllerClass{
tvc.model = self.model //the data you wanna populate the table view with. If the model is not from this current class, you can ingore this
}
}
}

//In tableview calss
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row % 2 != 0{
let cell = tableView.dequeueReusableCellWithIdentifier("SubIncomeCat", forIndexPath: indexPath) as! TableViewCell //or UITableViewCell if you have no custom calls for cells
}
let cell = tableView.dequeueReusableCellWithIdentifier(Storyboard.CellReusIdentifier, forIndexPath: indexPath) as! TableViewCell

// Configure the cell...
let rowContent = yourModel[indexPath.section][indexPath.row]
//now fill the cell with the content like...
//cell.textLabel?.text = rowContent.text
//cell.detailTextLabel?.text = rowContent.detail

return cell
}

关于xcode - 带有原型(prototype)单元格的 tableView.insertRowsAtIndexPaths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32918683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com