从两个不同的笔尖附加 tableview 自定义单元格 Swift
Appending tableview custom cells from two different nibs Swift
我有一个 uitableview
,其中包含两个自定义单元格 xib 文件(一个 uilabel
,第二个 uibutton
)。
我做什么 -
1. 我用三个单元格附加表视图(uilabel
- 第一个 xib)
2. 然后我加载第四个单元格 (with uibutton
- second 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 beginEditing]
、根据需要修改 table ui 和数据来动画更改,然后 [tableView commitChanges]
quick 方法是仅更新您的数据源并调用 [tableView reloadData]
尝试
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
我有一个 uitableview
,其中包含两个自定义单元格 xib 文件(一个 uilabel
,第二个 uibutton
)。
我做什么 -
1. 我用三个单元格附加表视图(uilabel
- 第一个 xib)
2. 然后我加载第四个单元格 (with uibutton
- second 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 beginEditing]
、根据需要修改 table ui 和数据来动画更改,然后 [tableView commitChanges]
quick 方法是仅更新您的数据源并调用 [tableView reloadData]
尝试
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