Bölümü yeniden başlatmaya ve bölümdeki hücre sayısını güncelleştirmeye çalışıyorum, ancak denediğimde hata alıyorum ve çöküyorum. 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)
}
}
Böylece temelde tarih takviminde dokunulduğunda, ben Array eklemek ve daha sonra hücrelerin sayısını güncelleştirmek: İşte kullanıyorum kodudur. Hücre içeriğini yapılandırdığım noktaya gelmedim, şu an sadece istediğim gibi çalıştığından emin olmaya çalışıyorum. Ben olsun hatadır:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
Ama sayar ve 2. yüzden kafam karıştı gösterir çünkü nedenini anlamıyorum.
_section_ 2 satır 2'yi yeniden yüklemeye çalıştığınız gibi görünüyor. "NSIndexSet (index: 0)' ı deneyin – brandonscript
[Özel durum kesme noktası] ekleyin (http://stackoverflow.com/questions/17802662/exception- Kritik-in-xcode) böylece nerede 'NSRangeException 'olduğunu görebiliriz. – user3480295