GCD를 사용하여 백그라운드 스레드에서 UITableView 데이터를로드하지만 사용자 정의 UITableViewCell의 데이터를 혼합합니다. 셀의 titleLabel 및 imageView는 문제가 없지만 모든 셀에서 textLabel (부제목)이 잘못되었습니다. 데이터가 메인 쓰레드에로드되고 데이터가 여러 배열로부터 온 것이 아니기 때문에 이런 일은 일어나지 않습니다. 그래서 나는 GCD를 사용하고 있기 때문에 추측 할 수 있습니다.GIT를 사용할 때 UITableViewCell의 데이터가 섞여 있습니다.
첫째, 나는 setUpTableForAlbumsFD 선택이
- (void)setUpTableForAlbumsFD
{
// __block CLProgressIndeterminateView *clP = [[CLProgressIndeterminateView alloc] initWithFrame:CGRectMake(325, tableScrollView.frame.size.height/2, 310, 20)];
// [tableScrollView addSubview:clP];
// [clP startAnimating];
type = @"Albums";
queryAlbums = [MPMediaQuery albumsQuery];
[queryAlbums setGroupingType:MPMediaGroupingAlbum];
mainArrayAlbum = [[NSMutableArray alloc] init];
otherArrayAlbum = [[NSMutableArray alloc] init];
theOtherArrayAlbum = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSArray *fullArray = [queryAlbums collections];
for (MPMediaItemCollection *collection in fullArray)
{
item = [collection representativeItem];
NSString *albumName = [item valueForProperty:MPMediaItemPropertyAlbumTitle];
NSString *albumArtist = [item valueForProperty:MPMediaItemPropertyArtist];
NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", albumName]];
Album *album = [[Album alloc] init];
album.albumTitle = albumName;
album.albumArtwork = [UIImage imageImmediateLoadWithContentsOfFile:filePath];
if (album.albumTitle.length > 4)
{
if ([album.albumTitle hasPrefix:@"The "])
{
album.albumOrderTitle = [album.albumTitle substringFromIndex:4];
}
else
{
album.albumOrderTitle = album.albumTitle;
}
}
else
{
album.albumOrderTitle = album.albumTitle;
}
album.albumArtist = albumArtist;
if (![mainArrayAlbum containsObject:album])
{
[mainArrayAlbum addObject:album];
}
}
}
앨범 사용자 정의 클래스는 데이터를 단지 컨테이너입니다 ... 그래서입니다
- (void)setUpTableForAlbums
{
dispatch_async(dispatch_get_global_queue(0, 0),^
{
[self setUpTableForAlbumsFD];
dispatch_async(dispatch_get_main_queue(),^
{
[albumTable reloadData];
});
});
}
... 그래서 같이 NSOperationQueue를 설정 .
cellForRowAtIndex 경로 방법은
MasterCellAlbum *albumCell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!albumCell)
{
albumCell = [[MasterCellAlbum alloc] initWithStyle:nil reuseIdentifier:@"Cell"];
}
alphabet = [self alphabet:@"album" withIndex:YES];
[albumCell setSelectionStyle:UITableViewCellEditingStyleNone];
NSString *alpha = [alphabet objectAtIndex:indexPath.section];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.albumOrderTitle beginswith[c] %@", alpha];
NSArray *predict = [mainArrayAlbum filteredArrayUsingPredicate:predicate];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Album *album1 = [predict objectAtIndex:indexPath.row];
albumCell.titleLabel.text = album1.albumTitle;
albumCell.textLabel.text = album1.albumArtist;
albumCell.avatarImageView.image = album1.albumArtwork;
longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(albumLittleMenu:)];
[albumCell addGestureRecognizer:longPress];
return albumCell;
내가 제대로 GCD를 사용하고 ... 그래서, 또는 내가 그 일을해야 또 다른 방법은 무엇입니까?
감사합니다. 나는 GCD를 사용하는 것에 익숙하지 않다. 대답 해줘서 고마워! 그들이 말하는 것에 대해 알고있는 사람이 내 코드를 분석하는 데 유용합니다! – Giz
그리고 hasPrefix 메서드가 존재하는지 전혀 몰랐습니다. – Giz
@Gizmoloon 좋은 코코아 개발자가되는 75 %는 프레임 워크가 무료로 제공하는 것을 알고 있습니다. 심지어 나는 그들 모두를 알지 못합니다 ... –