gpt4 book ai didi

ios - 从两个不同的 nibs Swift 附加 tableview 自定义单元格

转载 作者:行者123 更新时间:2023-11-29 01:42:41 25 4
gpt4 key购买 nike

我有一个 uitableview有两个自定义单元格 xib 文件(一个有 uilabel ,第二个有 uibutton )。
我做什么 -
1. 我将 tableview 附加到三个单元格(使用 uilabel - 第一个 xib)
2. 然后我加载第四个单元格(使用 uibutton - 第二个 xib)

uilabel文本是从数组中获取的,uibutton currentTitle也被获取,但来自另一个数组。

我的目标是 - 点击 uibutton它应该附加 1. 下一个单元格数组 uilabel和 2. 1 个带有 uibutton 的单元格来自相应的数组。

这是我的 tableview 代码

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return linesmain["start"]!.count + 1
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

if(indexPath.row < someTagsArray.count){
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell

cell.lblCarName.text = linesmain["start"]![indexPath.row]

return cell

} else {
var celle:vwAnswers = self.tableView.dequeueReusableCellWithIdentifier("cell2") as! vwAnswers
celle.Answer1.setTitle(answersmain["start"]![0], forState:UIControlState.Normal)
return celle
}}

我知道我应该使用类似 InsertRowsAtIndexPath 的东西,但我不知道如何在我的案例中正确实现它。

最佳答案

尝试

  tableView.beginUpdates()
var indexPath = NSIndexPath(forRow:row,inSection:0)
var indexPath2 = NSIndexPath(forRow:row,inSection:0)
self.tableView?.insertRowsAtIndexPaths([indexPath,indexPath2], withRowAnimation: UITableViewRowAnimation.Left)
tableView.endUpdates()

引用 Apple swift 示例:https://developer.apple.com/library/ios/samplecode/Lister/Listings/Swift_ListerToday_TodayViewController_swift.html

关于ios - 从两个不同的 nibs Swift 附加 tableview 自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32235383/

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