使用EventKit编辑特定事件 - Swift

时间:2017-07-19 17:15:29

标签: ios swift xcode eventkit

我想编辑一个从日历中获取的事件。我的问题是,我可以看到事件详细信息但编辑按钮没有显示,因此用户无法编辑它。

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
    }


        }

我希望它足够了! 很抱歉,如果Post中的内容不是核心,但这是我在SO上的第一篇文章。

1 个答案:

答案 0 :(得分:0)

问题解决了,我尝试使用 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
    }


        }

感谢您的帮助!祝你有愉快的一天