[英]Edit specific event with EventKit - Swift
I want to edit one event which i have fetched from a calendar. 我想编辑我从日历中获取的一个事件。 My problem is that i could see the event details but the edit button doesn't show up, so the user can't edit it.
我的问题是我可以看到事件详细信息,但是没有显示“编辑”按钮,因此用户无法对其进行编辑。
that's what i'm talking about 我正是这个意思
This is the relevant part of the Code 这是守则的相关部分
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
}
}
I hope it's enough! 我希望这足够了!
Sorry if something in the Post isn't corect but this is my first post on SO. 抱歉,如果Post中的内容不是核心内容,但这是我的第一篇SO文章。
Problem solved, i tried using eventIdentifier instead of a stored event and it worked. 问题解决了,我尝试使用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
}
}
Thanks for the help! 谢谢您的帮助! Have a nice day
祝你今天愉快
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.