0
내 앱에서 이벤트를 추가 할 수 있으며 해당 이벤트는 이벤트 정보가있는 셀로 tableView에 표시됩니다. 이제 이벤트의 날짜를 설정할 수있게하려면 그 날짜가 현재 날짜 (이벤트가 과거에 발생한 날짜)보다 이전 인 경우에만 셀이 tableView에 추가됩니다. Heres는 코드 :이벤트 셀의 날짜에 따라 이벤트 셀을 추가/추가하지 않는 방법
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let e = events[indexPath.row]
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell
let Date1 = e.eventDate
let Date2 = NSDate()
if Date1!.earlierDate(Date2).isEqualToDate(Date1!) {
// Sets labels in cell to whatever user typed in on the events page
cell.titlePrototypeCell!.text = e.eventTitle!
} else {
//Code to not add a cell
}
return cell
}
이 가진 문제는 이벤트 날짜가 (미래에) 현재 날짜 이후 인 경우 일반 세포가 전혀있는 tableView 대신없이 셀에 추가된다는 점이다. 이벤트가 미래에있을 경우 셀을 추가하지 않는 방법에 대한 아이디어가 있습니까?
동일한 논리를 사용하여 행 수에 사용하는 방법은 무엇입니까? 디버그 및 확인. 시간을 밀리 초 단위로 가져 와서 값을 비교하십시오. 그런 다음 확인하십시오. – Signare
데이터를 먼저 필터링해야합니다. –
날짜 비교를 위해이 SO Qn을 참조하십시오. http://stackoverflow.com/questions/26198526/nsdate-comparison-using-swift – Signare