我有一个包含用户帖子的表视图。每个帖子都有一张图片、用户名和帖子本身。刷新控件的操作是用Parse中的数据重新加载表。除了我拉动刷新时的极端延迟之外,一切都运行得很好。我不知道是因为每个单元格里的照片还是别的什么原因。如果有人知道为什么会这样,请让我知道。我会张贴的代码,如果有人需要它。
-(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];
}
}];
}发布于 2014-12-28 12:43:59
您正在后台线程中检索对象。
getFirstObjectInBackgroundWithBlock:此外,您正在尝试从后台线程更新您的UI。你只需要从主线程更新UI:
调用所有与UI相关的调用,如:
[userPostsTable reloadData];
[refreshControl endRefreshing];仅来自主线程。
使用:
dispatch_async(dispatch_get_main_queue(), ^{
// Update UI
});发布于 2014-12-28 12:43:50
假设您的代码片段是UITableViewController的一部分,则不应将refreshControl添加为tableView的subview。
-(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;
}https://stackoverflow.com/questions/27673599
复制相似问题