reloadSections UITableView Swift
reloadSections UITableView Swift
我正在尝试重新加载部分并更新部分中的单元格数量,但每次尝试时都会出现错误并崩溃。这是我使用的代码:
import UIKit
import CalendarView
import SwiftMoment
class TimeAwayRequestTableViewController: UITableViewController {
@IBOutlet var calendarView: CalendarView!
var selectedDates : [Moment] = []
override func viewDidLoad() {
super.viewDidLoad()
calendarView.delegate = self
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnInt = 0
if section == 0 {
returnInt = 2
}
if section == 1 {
returnInt = 1
}
if section == 2 {
print(selectedDates.count)
returnInt = selectedDates.count
}
return returnInt
}
}
extension TimeAwayRequestTableViewController : CalendarViewDelegate {
func calendarDidSelectDate(date: Moment) {
selectedDates.append(date)
print(selectedDates)
let section = NSIndexSet(index: 2)
self.tableView.beginUpdates()
self.tableView.reloadSections(section, withRowAnimation: .Automatic)
self.tableView.endUpdates()
}
func calendarDidPageToDate(date: Moment) {
print(date)
}
}
基本上,当在日历中点击日期时,我将其添加到数组中,然后更新单元格的数量。我还没有达到配置单元格内容的地步,现在我只是想确保它按我想要的方式工作。我得到的错误是:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
但我不明白为什么,因为它计数并显示 2。所以我很困惑。
我敢打赌你在 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
中使用了一些数组(包括 selectedDates
)并且超出了 bounds.Please 检查你的数据。
我正在尝试重新加载部分并更新部分中的单元格数量,但每次尝试时都会出现错误并崩溃。这是我使用的代码:
import UIKit
import CalendarView
import SwiftMoment
class TimeAwayRequestTableViewController: UITableViewController {
@IBOutlet var calendarView: CalendarView!
var selectedDates : [Moment] = []
override func viewDidLoad() {
super.viewDidLoad()
calendarView.delegate = self
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnInt = 0
if section == 0 {
returnInt = 2
}
if section == 1 {
returnInt = 1
}
if section == 2 {
print(selectedDates.count)
returnInt = selectedDates.count
}
return returnInt
}
}
extension TimeAwayRequestTableViewController : CalendarViewDelegate {
func calendarDidSelectDate(date: Moment) {
selectedDates.append(date)
print(selectedDates)
let section = NSIndexSet(index: 2)
self.tableView.beginUpdates()
self.tableView.reloadSections(section, withRowAnimation: .Automatic)
self.tableView.endUpdates()
}
func calendarDidPageToDate(date: Moment) {
print(date)
}
}
基本上,当在日历中点击日期时,我将其添加到数组中,然后更新单元格的数量。我还没有达到配置单元格内容的地步,现在我只是想确保它按我想要的方式工作。我得到的错误是:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
但我不明白为什么,因为它计数并显示 2。所以我很困惑。
我敢打赌你在 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
中使用了一些数组(包括 selectedDates
)并且超出了 bounds.Please 检查你的数据。