2014-12-28 2 views
0

사용자의 게시물이 포함 된 tableview가 있습니다. 각 게시물에는 사진, 사용자 이름 및 게시물 자체가 있습니다. 새로 고침 컨트롤의 동작은 Parse의 데이터로 테이블을 다시로드하는 것입니다. 내가 새로 고침 할 때 극단적 인 지연을 제외하고는 모든 것이 완벽하게 작동합니다. 나는 그것이 각 세포 또는 다른 것의 그림 때문에 그것이 었는지 나는 모른다. 왜 이런 일이 일어날 지에 대한 아이디어가 있다면 알려주십시오. 나는 누군가가 그것을 필요로한다면 코드를 게시 할 것이다.UIRefreshControl lagging

-(void)viewDidLoad { 

    refreshControl = [[UIRefreshControl alloc] init]; 
[refreshControl addTarget:self action:@selector(retrieveFromParse)  forControlEvents:UIControlEventValueChanged]; 
refreshControl.backgroundColor = [UIColor whiteColor]; 
refreshControl.tintColor = [UIColor colorWithRed:0.3878 green:0.5686 blue:1.0 alpha:0.9]; 
[userPostsTable addSubview:refreshControl]; 

} 


-(void) retrieveFromParse { 

PFQuery *quoteQuery = [PFQuery queryWithClassName:@"Quotes"]; 
quoteQuery.cachePolicy = kPFCachePolicyCacheThenNetwork; 
[quoteQuery orderByDescending:@"createdAt"]; 
[quoteQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) { 

    if (!error) { 

     NSString *category = [object objectForKey:@"Category"]; 

     if (category == nil) { 

      quoteLabel.font = [UIFont fontWithName:@"Helvetica Neue Light Italic" size:15]; 

     } 

     else { 

      quoteLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:15]; 

     } 

     quoteString = [object objectForKey:@"quoteContent"]; 
     quoteLabel.text = quoteString; 

     quoteIdString = object.objectId; 
     [refreshControl endRefreshing]; 


    } 

    else { 

     [refreshControl endRefreshing]; 
    } 
}]; 

PFQuery *userPostsQuery = [PFQuery queryWithClassName:@"userPosts"]; 
userPostsQuery.cachePolicy = kPFCachePolicyCacheThenNetwork; 
[userPostsQuery setLimit:300]; 
[userPostsQuery whereKey:@"quoteObjectId" matchesKey:@"objectId" inQuery:quoteQuery]; 
if (segmentedControl.selectedSegmentIndex == 0) { 

    [userPostsQuery orderByDescending:@"createdAt"]; 

} 
else { 

[userPostsQuery orderByDescending:@"likeCount"]; 

} 
[userPostsQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 

    if (!error) { 

     userPostsArray = [[NSArray alloc] initWithArray:objects]; 
     [userPostsTable reloadData]; 
     [refreshControl endRefreshing]; 

    } 

    else { 

     [refreshControl endRefreshing]; 
    } 
}]; 


} 
+1

는 아무 말도 할 수 없다. –

+0

죄송합니다. – bpomp87

+1

완료 블록 내의 코드가 주 스레드 또는 백그라운드 스레드에서 호출 되었습니까? 비록 내가 너무 많은 구문 분석에 익숙하지 않아도 그 문서가 주 스레드에서 호출되는지 아닌지를 말할 수는 없지만 문제가 될 수 있습니다. – Mike

답변

0

가정 당신의 코드 조각은 UITableViewController의 일부입니다, 당신은 tableViewsubview으로 refreshControl를 추가 할 수 없습니다.

-(void)viewDidLoad 
{ 
    refreshControl = [[UIRefreshControl alloc] init]; 
    [refreshControl addTarget:self action:@selector(retrieveFromParse)     
         forControlEvents:UIControlEventValueChanged]; 
    refreshControl.backgroundColor = [UIColor whiteColor]; 
    refreshControl.tintColor = [UIColor colorWithRed:0.3878 green:0.5686 blue:1.0 alpha:0.9]; 

    //This is causing the stutter 
    //[userPostsTable addSubview:refreshControl]; 
    //UIRefreshControl is meant to be used by a UITableViewController 
    self.refreshControl = refreshControl; 
} 
+0

나는 그것이 문제라고 생각하지 않는다. 이전에 다른 테이블 뷰에 추가 했으므로 제대로 작동했습니다. – bpomp87

1

백그라운드 스레드에서 개체를 검색하고 있습니다.

getFirstObjectInBackgroundWithBlock: 

또한 백그라운드 스레드에서 UI를 업데이트하려고합니다.

전화는 모든 UI 관련 통화가 좋아 : 메인 스레드 만에서

[userPostsTable reloadData]; 
[refreshControl endRefreshing]; 

당신은 메인 스레드에서 UI를 업데이트해야합니다.

는 사용 : 코드없이

dispatch_async(dispatch_get_main_queue(), ^{ 
    // Update UI 
}); 
+1

나는 그것을 시험해 보았다. 그리고 그것은 새로 고침을 더 매끄럽게하지 않았다. – bpomp87

+0

@ bpomp87 : 해당 메서드에서 코드를 제거 할 수 있으며 지연이 있는지 확인할 수 있습니까? 또한 이러한 메소드에 다른 코드가 있습니까? 당신은 dispatch_async 내부에서 모든 [[refreshControl endRefreshing]; –

+0

refreshFromParse 메서드가 아닌 새로 고침 컨트롤의 동작을 변경하면 지연이 발생하지 않습니다. 이러한 메소드에는 다른 코드가 없습니다. 그리고 예, 나는 [refreshControl endRefreshing]을 모두 만들었습니다. inside dispatch_async. – bpomp87