无法获得EKEventEditViewController的正确单元格

时间:2014-09-26 03:23:40

标签: swift

func test(button:UIButton){

    var alarm = EKAlarm(relativeOffset: 20)
    var event = EKEvent(eventStore: store)
    event.title = "xxxx"
    event.startDate = NSDate(timeIntervalSinceNow: 20)
    event.endDate = NSDate(timeIntervalSinceNow: 1000)
    event.calendar = calendarWithName(cal_name)
    event.alarms = [alarm]

    var ev = EKEventEditViewController()
    ev.event = event
    ev.eventStore = store
    ev.editViewDelegate = self
    ev.delegate = self

    self.presentViewController(ev, animated: true, completion: nil)
}

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {

    if (viewController.isKindOfClass(UITableViewController.self)){

        var tableview =  (viewController as UITableViewController).tableView

        println(tableview.numberOfSections())

        for i in 0...tableview.numberOfSections() {

              println(tableview.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: i)) != nil)

        }
    }
}

我正在使用EKEventEditViewDelegate,willShowViewController功能运行良好,我可以获得正确的表,但我无法获得第5节和下一节,代码有什么问题,我该如何解决这个问题。

控制台显示:

8

true

true

true

true

true

false

false

false

false

1 个答案:

答案 0 :(得分:0)

文档说cellForRowAtIndexPath(_:)只返回可见的单元格。

  

表示表格单元格的对象,如果单元格不是,则为nil   visible或indexPath超出范围。

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITableView_Class/index.html#//apple_ref/occ/instm/UITableView/cellForRowAtIndexPath