cellForRowAtIndexPath never called in UITableViewController

前端 未结 1 1798
感动是毒
感动是毒 2021-01-20 22:33

cellForRowAtIndexPath is never called (numberOfRowsInSection is) using UITableViewController with the following way:

import UIKit
import EventKit

class Even         


        
相关标签:
1条回答
  • 2021-01-20 23:13

    Replace your code in viewDidLoad with this.

    self.eventStore.requestAccessToEntityType(.Event) {
        (granted, error) -> Void in
    
        guard granted else { fatalError("Permission denied") }
    
        let endDate = NSDate(timeIntervalSinceNow: 604800)
        let predicate = self.eventStore.predicateForEventsWithStartDate(NSDate(),
                                                                        endDate: endDate,
                                                                        calendars: nil)
        self.eventsThisWeek = self.eventStore.eventsMatchingPredicate(predicate)
        dispatch_async(dispatch_get_main_queue(),{
    
            self.tableView.reloadData()
    
        })
        print(self.eventsThisWeek.count)
     }
    

    Your cellForRowAtIndexPath doesn't call because when your view is loaded at that time array was empty and when the self.eventStore.requestAccessToEntityType is completely executed and load array with new value you weren't notifying your tableView to reload the data as you have new values in your array.

    0 讨论(0)
提交回复
热议问题