gpt4 book ai didi

ios - 快速插入新的静态单元格表​​ View

转载 作者:行者123 更新时间:2023-11-29 00:46:18 26 4
gpt4 key购买 nike

想要添加新的单元格。我怎样才能做到这一点?请帮忙!我尝试一下

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 1 {
return 3 + eventDates.count
} else {
return super.tableView(tableView, numberOfRowsInSection: section)
}
}


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (indexPath.section == 0 && indexPath.row == 1) {
eventDaysVisible = !eventDaysVisible
tableView.reloadData()

tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: eventDates.count + 3, inSection: 0)], withRowAnimation: .Automatic)
tableView.reloadData()
}

for day in eventDates {
print("OBJ: \(day)")
}

tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

我有 3 个静态单元格,如果我切换按钮,则需要在第一个单元格之后插入新单元格。

var eventdates =  Friday, Saturday, Sunday

希望你能帮助我。

最佳答案

import UIKit

class ViewController: UIViewController {

var cellCount = 1

@IBOutlet weak var tableView: UITableView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

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


}


extension ViewController:UITableViewDataSource {

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return cellCount
}

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

let cell = UITableViewCell()

cell.backgroundColor = UIColor.grayColor()

return cell

}

func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

let eventDates = ["1", "2", "3"]

var indexPathsArray = [NSIndexPath]()

for rowCount in 0 ..< eventDates.count {
indexPathsArray.append(NSIndexPath(forRow: rowCount, inSection: 0))
cellCount += 1
}

tableView.beginUpdates()
tableView.insertRowsAtIndexPaths(indexPathsArray, withRowAnimation: .Automatic)
tableView.endUpdates()

tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

}

关于ios - 快速插入新的静态单元格表​​ View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38571455/

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