gpt4 book ai didi

ios - UIRefreshControl 滞后

转载 作者:行者123 更新时间:2023-11-29 02:24:57 29 4
gpt4 key购买 nike

我有一个包含用户帖子的表格 View 。每个帖子都有图片、用户名和帖子本身。刷新控件的操作是使用来自 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];
}
}];


}

最佳答案

您正在后台线程中检索对象。

getFirstObjectInBackgroundWithBlock:

您还试图从后台线程更新您的用户界面。您只需要从主线程更新 UI:

调用所有与 UI 相关的调用,例如:

[userPostsTable reloadData];
[refreshControl endRefreshing];

仅来自主线程。

使用:

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

关于ios - UIRefreshControl 滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27673599/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com