使用EventKit编辑特定事件 - Swift

问题描述:

我想编辑一个从日历中获取的事件。我的问题是,我可以看到事件的详细信息,但编辑按钮不显示,所以用户不能编辑它。使用EventKit编辑特定事件 - Swift

that's what i'm talking about

这是代码的相关部分

class ViewController: UIViewController, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource, EKEventEditViewDelegate { 

let eventStore = EKEventStore() 
var hibakURL = [String]() 
var hibasEventek = [EKEvent]() 

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
      if segue.identifier == "segue" { 
       // Configure the destination event view controller 
       let eventViewController = segue.destination as! EKEventViewController 
       // Fetch the index path associated with the selected event 
       let indexPath = self.hibaTableView.indexPathForSelectedRow! 
       // Set the view controller to display the selected event 
       eventViewController.event = self.hibasEventek[indexPath.row] 
       print(indexPath.row) 

       // Allow event editing 
       eventViewController.allowsEditing = true 
      } 
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    { 
     let numofRows = hibakURL.count 
     return numofRows 
    } 

    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
    { 
     let cell = hibaTableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 
     cell.textLabel?.text = hibasEventek[indexPath.row].title 

     cell.textLabel?.font = UIFont(name: (cell.textLabel?.font.fontName)!, size:14) 

     return cell 
    } 


     } 

我希望这是不够的!
对不起,如果在帖子中的东西不corect,但这是我的第一篇文章。

问题解决了,我尝试使用eventIdentifier而不是存储的事件,它的工作。

class ViewController: UIViewController, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource, EKEventEditViewDelegate { 

let eventStore = EKEventStore() 
var hibakURL = [String]() 
var hibasEventek = [String]() // <-- To Store eventIdentifier 

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
      if segue.identifier == "segue" { 
       // Configure the destination event view controller 
       let eventViewController = segue.destination as! EKEventViewController 
       // Fetch the index path associated with the selected event 
       let indexPath = self.hibaTableView.indexPathForSelectedRow! 
       // Set the view controller to display the selected event 
       eventViewController.event = eventStore.event(withIdentifier: hibasEventek[indexPath.row])! //it fetches now that specific event from the eventStore instead of a copied event 
       print(indexPath.row) 

       // Allow event editing 
       eventViewController.allowsEditing = true 
      } 
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    { 
     let numofRows = hibakURL.count 
     return numofRows 
    } 

    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
    { 
     let cell = hibaTableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 
     cell.textLabel?.text = hibasEventek[indexPath.row].title 

     cell.textLabel?.font = UIFont(name: (cell.textLabel?.font.fontName)!, size:14) 

     return cell 
    } 


     } 

感谢您的帮助!祝你有美好的一天