首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从数组EKEvent获取iOS

从数组EKEvent获取iOS
EN

Stack Overflow用户
提问于 2015-08-31 22:38:23
回答 1查看 245关注 0票数 0

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

但是,如果我在一个表视图( (-(IBAction)button:(UiButton *)sender) )的按钮中做了这个操作,它就会得到一个EKEvent,但是没有注意到这个事件。

这是我的代码:

代码语言:javascript
复制
EKEvent *event =[eventArray objectAtIndex:0]
NSString *string = event.notes

这是完整的代码:

代码语言:javascript
复制
- (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];

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-31 22:59:46

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

你的手机是从模型中加载的。事件数据可能在模型中。

如果您的按钮或单元格需要访问事件数据,您必须决定数据如何通过您的应用程序。您还希望事件有一个单一的真实来源,因此无论您的应用程序的状态如何,您总是可以确定事件的详细信息,无论是编辑、更新、持久化、删除或插入事件。

这些都是您想要解决的问题,因此您非常了解如何存储这些细节,以及您的单元格按钮应该如何访问事件的备注。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32320971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档