gpt4 book ai didi

ios - EKEventEditViewController中响应 "cancel"或 "Done"

转载 作者:可可西里 更新时间:2023-11-01 05:23:17 24 4
gpt4 key购买 nike

我正在使用 EKEventEditViewController,我可以用我需要的信息填充它。我被授予访问日历和所有内容的权限。我的问题是当我点击“取消”时没有任何反应。当我点击“完成”时,我收到一条错误消息,提示未设置日历、未设置日期以及“该事件不属于该事件存储”。

我认为我的 didCompleteWithAction 委托(delegate)方法没有被调用。

我的 viewController 符合:

@interface EventoViewController : UIViewController <EKEventEditViewDelegate>

当我尝试将自己设置为委托(delegate)时出现错误:

sending EventoViewController *const__strong' to parameter of incompatible type 'id<UINavigationControllerDelegate>'

原代码.h

#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

@interface EventoViewController : UIViewController <EKEventEditViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *eventDetailTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *eventDetailDateLabel;
@property (weak, nonatomic) IBOutlet UILabel *eventDetailDescriptionLabel;


- (IBAction)closeModalView:(id)sender;
- (IBAction)addEventToNative:(id)sender;


@end

原创.m

#import "EventoViewController.h"



@implementation EventoViewController

@synthesize eventDetailTitleLabel, eventDetailDateLabel, eventDetailDescriptionLabel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad { [super viewDidLoad]; }

- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; }

- (IBAction)closeModalView:(id)sender { [self dismissModalViewControllerAnimated:YES]; }

- (IBAction)addEventToNative:(id)sender {
NSLog(@"Clicked ");
EKEventStore *eventStore = [[EKEventStore alloc] init];

if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

// perform the main thread here to avoid any delay. normally seems to be 10 to 15 sec delay.
[self performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:NO];



if (granted){
NSLog(@"We are granted to access Calendars!");
//---- codes here when user allow your app to access theirs' calendar.

}
else {
//---- code for no permission
NSLog(@"We have no permission to access calendars!");
}
}];
}
}

- (void)presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore {
EKEventEditViewController* eventEditVC = [[EKEventEditViewController alloc] init];
eventEditVC.eventStore = eventStore;

EKEvent* event = [EKEvent eventWithEventStore:eventStore];
event.title = self.eventDetailTitleLabel.text;
event.startDate = [NSDate date];
event.endDate = [NSDate date];
event.URL = [NSURL URLWithString:@"http://portalsatuat.plataforma.sat.gob.mx/m/sp/paginas/home.aspx"];
event.notes = @"Evento SAT";
event.allDay = YES;
eventEditVC.event = event;

//eventEditVC.delegate = (id)self;
[self presentViewController:eventEditVC animated:YES completion:nil];
}


- (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action {
NSLog(@"Clicked Cancel or Done");
[self dismissModalViewControllerAnimated:YES];
}

- (void)eventViewController:(EKEventViewController *)controller didCompleteWithAction:(EKEventViewAction)action {
NSLog(@"No se que esta pasando aqui!");
}

- (void)viewDidUnload {
[self setEventDetailTitleLabel:nil];
[self setEventDetailDateLabel:nil];
[self setEventDetailDescriptionLabel:nil];
[super viewDidUnload];
}

@end

最佳答案

您需要将 View Controller 类中的 self 分配给 Controller 上的 editViewDelegate 属性 - EKEventEditViewController 类是 UINavigationController 的子类,因此继承的委托(delegate)属性用于处理导航事件。希望对您有所帮助。

- (void)presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore {
EKEventEditViewController* eventEditVC = [[EKEventEditViewController alloc] init];
eventEditVC.eventStore = eventStore;
// Add this line:
eventEditVC.editViewDelegate = self;

关于ios - EKEventEditViewController中响应 "cancel"或 "Done",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13383827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com