是否可以在EKCalendarChooser中显示启用添加新日历,就像默认的iPhone日历应用在左上角显示+并允许您定义日历一样?
答案 0 :(得分:2)
经过大量的试验和错误, 我终于明白了:
var calendarChooser: EKCalendarChooser!
var navController: UINavigationController!
func setup () {
calendarChooser = EKCalendarChooser(
selectionStyle: EKCalendarChooserSelectionStyleMultiple,
displayStyle: EKCalendarChooserDisplayAllCalendars,
entityType: EKEntityTypeEvent,
eventStore: zeitplanController.cache.eventStore)
// DON'T DO THE FOLLOWING:
// calendarChooser.editing = false
navController = UINavigationController(rootViewController: calendarChooser)
calendarChooser.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit, target: self, action: "startEditing")
}
func startEdit () {
calendarChooser.editing = true
calendarChooser.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "endEdit") }
func endEdit () {
calendarChooser.editing = false
calendarChooser.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit, target: self, action: "startEdit")
}
这个放在UIPopoverController中显示标准的Calendar Chooser对话框,包括编辑功能,就像在原始日历应用程序中一样。
@Apple:请帮我们帮忙并更新文档,让我们的生活更轻松
答案 1 :(得分:1)
我一直在寻找相同的即用型解决方案,差不多一天,到目前为止没有运气..
但是,好的是你可以打电话
[yourEKCalendarChooserInstance setEditing:YES];
它会显示“添加日历”行
但糟糕的是,点击/选择没有任何反应。 这就是我到目前为止所发现的全部内容
更新:
这段代码对我有用(到目前为止只在模拟器上测试):
EKEventStore *store = [[[EKEventStore alloc] init] autorelease];
EKCalendarChooser *chooser = [[EKCalendarChooser alloc] initWithStyle:EKCalendarChooserSelectionStyleSingle displayStyle:EKCalendarChooserDisplayWritableCalendarsOnly eventStore:store];
[chooser setEditing:YES];
[chooser setShowsDoneButton:YES];
[chooser setShowsCancelButton:YES];
UINavigationController *modalController = [[UINavigationController alloc] initWithRootViewController:chooser];
[self presentViewController:modalController animated:YES completion:nil];
此外,当然,您需要为完成/取消按钮提供代理。