У меня возникает одна проблема относительно того, что ячейки UITableView смешиваются при прокрутке, особенно для изображений.iOS: ячейки UITableView смешиваются при прокрутке
Я не уверен, почему это происходит.
У меня есть переменная для отображения, а затем ее смешивание.
Ниже мой код.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"FriendsCell";
FriendsTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FriendsTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
FriendsTableCell *simpleTableCell = (FriendsTableCell *)cell;
_model = [_contentArray objectAtIndex:indexPath.row];
simpleTableCell.nameLabel.text = _model.fullname;
if(_friendsSegmentControl.selectedSegmentIndex == 0) {
simpleTableCell.followButton.hidden = NO;
simpleTableCell.removeButton.hidden = NO;
simpleTableCell.unBlockButton.hidden = YES;
simpleTableCell.ignoreRequest_btn.hidden = YES;
simpleTableCell.rejectRequest_btn.hidden = YES;
simpleTableCell.acceptRequest_btn.hidden = YES;
simpleTableCell.removeButton.tag = indexPath.row;
[simpleTableCell.removeButton addTarget:self action:@selector(deleteFriend_btn:) forControlEvents:UIControlEventTouchUpInside];
simpleTableCell.followButton.tag = indexPath.row;
if([_model.isfollowed isEqualToString:@"YES"]) {
[simpleTableCell.followButton setImage:[UIImage imageNamed:@"follow_yellow.png"] forState:UIControlStateNormal];
[simpleTableCell.followButton addTarget:self action:@selector(unfollowFriend_btn:) forControlEvents:UIControlEventTouchUpInside];
}
else {
[simpleTableCell.followButton setImage:[UIImage imageNamed:@"follow_white.png"] forState:UIControlStateNormal];
[simpleTableCell.followButton addTarget:self action:@selector(followFriend_btn:) forControlEvents:UIControlEventTouchUpInside];
}
}
NSString *escapedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef) _model.prof_pic,NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8));
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.touristtube.com/%@",escapedString]]];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
simpleTableCell.profileImageView.image = image;
});
});
}
Вы извлекаете данные изображения асинхронно. К моменту завершения поиска ячейка повторно используется для другой строки. – Paulw11
Хорошо, так что, похоже, решение, нужно ли мне прямое изображение изображения, пожалуйста, помогите мне на этом – Kashif
@ Paulw11, вы абсолютно правы. –