2013-06-03 1 views
1

캘린더가 표시된 상태에서 앱을 만들려고합니다. 캘린더에서 매일 (탭 제스처가있는 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; 
} 

여기 내 코드입니다.

+3

가 시간을내어되고 있는지 확인하려면 몇 가지 프로파일 링을 수행 여기에 그 일을의 올바른 방법을 보여줍니다 링크입니다. – Wain

+0

얼마나 많은 이벤트를 가져올 수 있습니까? – NeverBe

+0

느림은 UITableview입니다. 이벤트 배열은 정말 빨리 채워지고 인쇄됩니다 (NSLog를 통해). 그런 다음 테이블 뷰가 표시되거나 테이블 뷰 대리자 함수가 호출되기 전에 긴 일시 중지가 발생합니다. 매일 평균 3-5 건의 이벤트가 발생하지만 많지는 않습니다. –

답변

0

답변을 찾았습니다. 여기서 문제는 다음과 같습니다. [store requestAccessToEntityType : EKEntityTypeEvent completion :^(BOOL 부여, NSError * 오류) {

iOS6 및 iOS5에서 이벤트 저장소에 액세스하는 방식이 다릅니다.

http://fostah.com/ios/2012/09/28/ios6-event-edit.html

0

프로파일 링을하지 않으면 코드의 병목 현상이 무엇인지 말할 수 없습니다. 그러나 이전 경험을 바탕으로 나는 그것이 + 20000x (또는 무언가)라고 적어도 경우

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

두 번째처럼 보이는 선이라고 말할 것입니다. 무엇보다도 먼저 이것을 쓰는 것이 더 편리 할 것입니다.

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

하지만이 방법은 프로그램 속도를 크게 높이 지 않을까 우려됩니다. 일반 C 코드로 돌아가서 예를 들어 사용하는 것이 좋습니다. sprintf 대신 here의 구문과 사용 예제를 조회 할 수 있습니다.

관련 문제