gpt4 book ai didi

iOS解析个人资料图片上的黑条(PFImageView)

转载 作者:行者123 更新时间:2023-11-29 12:14:45 25 4
gpt4 key购买 nike

我正在使用 Parse 作为我的应用程序的后端,个人资料照片似乎没有正确显示,如图所示: notice the john appleseed

john_appleseed 的照片上有一条黑条。

这是我保存头像的代码:

NSData *profileData = UIImagePNGRepresentation(cell1.profileView.image);
PFFile *profileFile = [PFFile fileWithName:@"profilePhoto" data:profileData];
[profileFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
if (succeeded)
{
[user setObject:profileFile forKey:@"profilePhoto"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{

}
else
{

}
}];
}
}
}];

这是我检索图像的方式:(在 PFQueryTableViewController 中)

- (PFQuery *)queryForTable
{
//NSLog(@"called");
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString *filter = [defaults objectForKey:@"topicFilter"];
NSLog(@"queryfortable: %@", filter);
PFQuery *query = [PFQuery queryWithClassName:@"Questions"];
[query includeKey:@"user"];
[query whereKey:@"category" equalTo:filter];
[query orderByDescending:@"createdAt"];
return query;
}

- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == self.objects.count)
{
return nil;//this is for the load more cell.
}
return [self.objects objectAtIndex:indexPath.section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object

PFUser *user = [object objectForKey:@"user"];
PFImageView *profileImgView = (PFImageView *)[cell viewWithTag:1];
profileImgView.layer.cornerRadius = profileImgView.frame.size.height/2;
profileImgView.layer.masksToBounds = YES;
PFFile *file = user[@"profilePhoto"];
profileImgView.file = file;
[profileImgView loadInBackground];

有什么想法吗?非常感谢。

最佳答案

您应该在主线程上更新用户界面。因为你在后台加载一些东西,你应该通知主线程它需要更新一个对象。 loadInBackground 正在异步下载文件。

这是一个示例,您可以根据需要进行更改,只是为了说明,在回调中更新 UI 组件有它的好处;这是基于 Parses 自己的 AnyPic :

NSString *requestURL = file.url; // Save copy of url locally (will not change in block)

[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
//dispatch on main thread
UIImage *image = [UIImage imageWithData:data];
} else {
NSLog(@"Error on fetching file");
}
}];

关于iOS解析个人资料图片上的黑条(PFImageView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32300666/

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