캘린더가 표시된 상태에서 앱을 만들려고합니다. 캘린더에서 매일 (탭 제스처가있는 UIView입니다) 탭을 클릭하면 해당 날짜의 모든 캘린더 약속이 표시됩니다. UITableView에 표시됩니다. 나는이 작업을하고 있지만 탭이 발생하는 시점과 실제로 데이터가 UITableView에 채워지는 시점 사이에 큰 차이가있다.UITableView Population Slowness
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];
}];
jQuery과 위임 기능 : 어떤 도움을 크게 감상 할 수
- (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;
}
여기 내 코드입니다.
가 시간을내어되고 있는지 확인하려면 몇 가지 프로파일 링을 수행 여기에 그 일을의 올바른 방법을 보여줍니다 링크입니다. – Wain
얼마나 많은 이벤트를 가져올 수 있습니까? – NeverBe
느림은 UITableview입니다. 이벤트 배열은 정말 빨리 채워지고 인쇄됩니다 (NSLog를 통해). 그런 다음 테이블 뷰가 표시되거나 테이블 뷰 대리자 함수가 호출되기 전에 긴 일시 중지가 발생합니다. 매일 평균 3-5 건의 이벤트가 발생하지만 많지는 않습니다. –