【发布时间】:2019-04-12 15:26:39
【问题描述】:
在同一个viewController 中,我有一个calendarTableView,代表一个月的日子。在cellForRowAti 选择对应于当天的行并调用函数来填充timeSlotCollectionView。一切正常,但我有一点奇怪的情况。
案例 1:行 height = auto 和 scrollPosition.none = timeSlotCollectionView 不关注 cornerRadius
案例 2:行 height = auto 和 scrollPosition.middle = 线程 1:calendarTableViewcell 定义上的 EXC_BAD_ACCESS(代码=2,地址=0x659ef4)
案例3:行height = 44 和scrollPosition.none = calendarTableViewcell 不关注cornerRadius
案例 4:行 height = 44 和 scrollPosition.middle = calendarTableViewcell 不关注 cornerRadius
案例 5:行 height = 60 和 scrollPosition.none = calendarTableViewcell 跟随 cornerRadius
案例 6:行 height = 60 和 scrollPosition.middle = calendarTableViewcell 不要再次关注 cornerRadius..
我不介意行高为 60,但scrollPosition必须是.middle 否则我不会看到当天的行..
你能看出我做错了吗?我搜索了其他帖子,但找不到任何可以让我知道问题所在的线索。
像往常一样非常感谢。
这是calendarTableView函数:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "calendarCell", for: indexPath) as! CalendarTableViewCell
// Configure the cell...
let date = datesArray[indexPath.row]
print(date)
let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day, .weekday], from: date)
cell.dayLabel.text = "\(String(describing: components.day!))" + " " + "\(dayNamesArray[components.weekday! - 1])"
cell.cellWeekday = components.weekday!
print("cell weekday is: \(cell.cellWeekday!)") // prints correct weekday
cell.cellId = "\(String(format:"%04d", components.year!))" + "\(String(format:"%02d", components.month!))" + "\(String(format:"%02d", components.day!))"
self.selectedDate = cell.cellId // used for time slots cellId
print("##################### selectedDate in tableview is :\(self.selectedDate) ")
// highlighting current day cell
if indexPath.row == self.actualDay - 1 && self.actualMonth == self.displayedMonth {
cell.dayLabel.backgroundColor = UIColor.red.withAlphaComponent(0.3)
// emulate user selecting the cell
tableView.selectRow(at: indexPath, animated: false, scrollPosition: UITableViewScrollPosition.none) // changing to .middle makes the tableview go looping
print(" @@@@@@@@@@@@@@@@@@@@@@@@@@ selected cell weekday is: \(cell.cellWeekday!) @@@@@@@@@@@@@@@@@@@@ ")
// self.updateTimeSlots(selectedCell: cell)
// self.actualWeekday = cell.cellWeekday! // nil error
self.selectedDate = cell.cellId
// calculateOpenTimeSlots()
}
// let cornerRadius: CGFloat = 5
// cell.layer.cornerRadius = cornerRadius
// cell.clipsToBounds = true
// self.updateTimeSlots(selectedCell: cell)
return cell
}
【问题讨论】:
标签: ios swift uitableview uicollectionview