1
私は静的なテーブルビューの中に動的なテーブルビューを持っていますが、私は2番目のテーブルビューで呼び出すときにcellForRowAtIndexPathを呼び出すreloadDataを取得できません。 2番目のテーブルビューにCellデータを挿入する必要がある方法はありますか?それとももっと良い方法がありますか?私はそれが役立つかどうかを見るためにビジュアルを付けました。複数のtableView reloadData()
import UIKit
import CalendarView
import SwiftMoment
class TimeAwayRequestTableViewController: UITableViewController {
@IBOutlet var calendarView: CalendarView!
@IBOutlet weak var selectedTableView: UITableView!
var selectedDates : [Moment] = []
override func viewDidLoad() {
super.viewDidLoad()
calendarView.delegate = self
selectedTableView.delegate = self
selectedTableView.dataSource = self
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnInt = 0
if tableView == selectedTableView {
returnInt = 10
} else {
if section == 0 {
returnInt = 2
}
if section == 1 {
returnInt = 1
}
}
return returnInt
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
var numberOfSections = 0
if tableView == selectedTableView {
numberOfSections = 0
} else {
numberOfSections = 2
}
return numberOfSections
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell()
if tableView == selectedTableView {
cell = self.tableView.dequeueReusableCellWithIdentifier("dateCell")!
let dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .ShortStyle
dateFormatter.timeStyle = .NoStyle
let date = selectedDates[indexPath.row].date
cell.textLabel?.text = dateFormatter.stringFromDate(date)
} else {
cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
}
return cell
}
}
extension TimeAwayRequestTableViewController : CalendarViewDelegate {
func calendarDidSelectDate(date: Moment) {
selectedDates.append(date)
print(selectedDates)
selectedTableView.frame.size.height = CGFloat(selectedDates.count) * CGFloat(44)
self.tableView.contentSize.height = self.tableView.frame.size.height + self.selectedTableView.frame.size.height
}
func calendarDidPageToDate(date: Moment) {
print(date)
}
}
numbeOfSectionsInTableViewから0ではなく1を返します。 –