gpt4 book ai didi

ios - 从数组 iOS 获取 EKEvent

转载 作者:行者123 更新时间:2023-11-29 01:41:43 24 4
gpt4 key购买 nike

我想从数组 iOS 中获取 EKEvent。但我有一个问题。如果我将我的代码行放在 viewDidLoad 方法中,它就可以工作。

但是如果我在 TableView 的按钮中创建它:(-(IBAction)button:(UiButton *)sender) 它会得到一个 EKEvent,但不会记录该事件。

那是我的代码:

EKEvent *event =[eventArray objectAtIndex:0]
NSString *string = event.notes

这就是完整的代码:

- (void)viewDidLoad {

selectedDate = [NSDate date];

[super viewDidLoad];

EKEventStore *store = [[EKEventStore alloc] init];

[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted == NO) {

UIViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"needAccess"];
[self.view addSubview:controller.view];
[self addChildViewController:controller];

}
}];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDate *start = [calendar dateBySettingHour:0 minute:0 second:0 ofDate:selectedDate options:0];
NSDate *end = [calendar dateBySettingHour:0 minute:0 second:0 ofDate:[selectedDate dateByAddingTimeInterval:60*60*24] options:0];

NSPredicate *predicate = [store predicateForEventsWithStartDate:start endDate:end calendars:nil];
eventArray = [store eventsMatchingPredicate:predicate];


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [eventArray count];
}

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [table dequeueReusableCellWithIdentifier: @"EventCell"];

EKEvent *event = [eventArray objectAtIndex:indexPath.row];

UIButton *headline = (UIButton *)[cell viewWithTag:1];

headline.layer.cornerRadius = headline.frame.size.width / 2;
headline.clipsToBounds = YES;

headline.tag = indexPath.row;
[headline addTarget:self action:@selector(headlineButton:) forControlEvents:UIControlEventTouchUpInside];

return cell;
}

-(void)headlineButton:(UIButton*)sender {

EKEvent *event = [eventArray objectAtIndex:0];
NSArray *notes = [event.notes componentsSeparatedByString:@"//"];


NSString *latitude = [notes objectAtIndex:1];
NSString *longitude = [notes objectAtIndex:2];

}

最佳答案

这可能是因为单元格或单元格上的按钮都没有 EKEvent 属性。

您的单元格是从模型中加载的。事件数据很可能在模型中

如果您的按钮或单元格需要访问事件数据,您必须决定数据如何流经您的应用。您还希望拥有事件的单一真实来源,因此无论您的应用处于何种状态,您始终可以确定事件的详细信息,无论是编辑、更新、持久保存、删除还是插入事件。

这些是您可能想要解决的问题,因此您非常了解存储这些详细信息的位置和方式,以及您的单元格按钮应如何访问事件的注释。

关于ios - 从数组 iOS 获取 EKEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32320971/

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