1

カレンダーが表示されているアプリを作成しようとしていますが、カレンダーの 1 日 (毎日がタップ ジェスチャの UIView) がタップされるとすぐに、その日のすべてのカレンダーの予定が UITableView に表示されます。私はこれを機能させましたが、タップが発生してからデータが実際に UITableView に入力されるまでの間に大きな遅れがあります。これが私のコードです:

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

//Access Granted to Calendar by user
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

// Create the start date components
NSDateFormatter *startFormatter = [[NSDateFormatter alloc]init];
[startFormatter setDateFormat:@"MM/dd/yyyy hh:mm a"];

NSString *monthNumberString = [NSString stringWithFormat:@"%i", month];

NSString *startDateString = [[[[[monthNumberString stringByAppendingString:@"/"] stringByAppendingString:dLabel.text] stringByAppendingString:@"/"] stringByAppendingString:yearString] stringByAppendingString:@" 12:01 am"];

NSDate *start = [startFormatter dateFromString:startDateString];

NSLog(@"Start Date: %@", startDateString);

// Create the end date components
NSDateFormatter *endFormatter = [[NSDateFormatter alloc]init];
[endFormatter setDateFormat:@"MM/dd/yyyy hh:mm a"];

NSString *endDateString = [[[[[monthNumberString stringByAppendingString:@"/"] stringByAppendingString:dLabel.text] stringByAppendingString:@"/"] stringByAppendingString:yearString] stringByAppendingString:@" 11:59 pm"];

NSDate *end = [endFormatter dateFromString:endDateString];
NSLog(@"End Date: %@", endDateString);

// Create the predicate from the event store's instance method
NSPredicate *predicate = [store predicateForEventsWithStartDate:start
                                                            endDate:end
                                                          calendars:nil];


// Fetch all events that match the predicate
events = [store eventsMatchingPredicate:predicate];

//Sort the array
events = [events sortedArrayUsingSelector:@selector(compareStartDateWithEvent:)];

int eventCount = [events count];

NSLog(@"%i", eventCount);

for (int i=0; i<eventCount; i++) {
    EKEvent *theEvent = [events objectAtIndex:i];    
    NSLog (@"Element %i = %@", i, theEvent.title);
}

UITableView *dayTableView = [[UITableView alloc] initWithFrame:CGRectMake(360, 0, 300, 550)
                                                                 style:UITableViewStylePlain];
dayTableView.backgroundColor = lightBlueColor;
dayTableView.separatorColor = [UIColor clearColor]; 
dayTableView.delegate = self;
dayTableView.dataSource = self;

[super addSubview:dayTableView];

}];

UITableviewデリゲート関数:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog (@"I made a section!");
    return 1;    //count of section


}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSLog (@"I made %i rows!", [events count]);
    return [events count];
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *c = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mycell"];

    EKEvent *theEvent = [events objectAtIndex:indexPath.row];

    c.textLabel.text = theEvent.title;

    NSLog (@"Cell %i = %@", indexPath.row, theEvent.title);



    //c.textLabel.text = @"Calendar Event Goes Here";
    c.textLabel.textColor = [UIColor whiteColor];

     //NSLog (@"I made a cell!");

    return c;    


}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{




    return 35;
}

どんな助けでも大歓迎です。

4

2 に答える 2