사용자 정의 프로토 타입 셀이있는 UITableViewController가 있습니다. 프로토 타입 셀 안에는 2 개의 라벨과 이미지가 있습니다. 이미지의 경우 100, 라벨의 경우 101 및 102로 태그가 지정됩니다. 내가 heres는이 방법viewWithTag는 cellForRowAtIndexPath 메서드 내에서 nil을 반환합니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] == 0) {
static NSString *CellIdentifier = @"InfoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIImageView *albumArtworkImageView = (UIImageView *)[cell viewWithTag:100];
albumArtworkImageView.image = [self getAlbumArtworkWithSize:albumArtworkImageView.frame.size];
UILabel *albumArtistLabel = (UILabel *)[cell viewWithTag:101];
albumArtistLabel.text = [self getAlbumArtist];
UILabel *albumInfoLabel = (UILabel *)[cell viewWithTag:102];
albumInfoLabel.text = [self getAlbumInfo];
return cell;
} else {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
MPMediaQuery *audiobookQuery = [MPMediaQuery audiobooksQuery];
MPMediaPropertyPredicate *albumPredicate = [MPMediaPropertyPredicate predicateWithValue: audiobookTitle forProperty: MPMediaItemPropertyAlbumTitle];
[audiobookQuery addFilterPredicate:albumPredicate];
NSArray *albumTracks = [audiobookQuery items];
NSUInteger trackNumber = [[[albumTracks objectAtIndex:(indexPath.row-1)] valueForProperty:MPMediaItemPropertyAlbumTrackNumber] unsignedIntegerValue];
if (trackNumber) {
cell.textLabel.text = [NSString stringWithFormat:@"%i. %@", trackNumber, [[[albumTracks objectAtIndex:(indexPath.row-1)] representativeItem] valueForProperty:MPMediaItemPropertyTitle]];
} else {
cell.textLabel.text = [[[albumTracks objectAtIndex:(indexPath.row-1)] representativeItem] valueForProperty:MPMediaItemPropertyTitle];
}
if ([self sameArtists]) {
cell.detailTextLabel.text = @"";
} else {
if ([[[albumTracks objectAtIndex:(indexPath.row-1)] representativeItem] valueForProperty:MPMediaItemPropertyArtist]) {
cell.detailTextLabel.text = [[[albumTracks objectAtIndex:(indexPath.row-1)] representativeItem] valueForProperty:MPMediaItemPropertyArtist];
} else {
cell.detailTextLabel.text = @"";
}
}
return cell;
}
}
내부에 나는 데 스토리 보드
문제를 살펴 그 태그에 액세스하려고하면 내가있는 태그에서보기를 찾아 줄입니다 반환 없음. 전에 이런 유형의 조회를했는데 왜 그들이 nil을 반환하는지 알 수 없습니다. 어떤 도움을 주시면 감사하겠습니다. 나는 디버깅하기에 좋은 방법조차 모르겠다. 저는 C# 개발자로서 객관적인 -c/ios 프로그래밍을 배우려고합니다. 감사!
'[cell.contentView viewWithTag : 101]'(으)로 변경하십시오. 모든 하위보기는 셀의 내용보기에 있어야하며 셀에는 직접 나타나지 않아야합니다. – rmaddy
나는 그것을 시도했다. 그러나 그것은 아직도 돌아 오지 않고있다. 내가 틀리게 할 수있는 다른 건? – user1585542
viewWithTag :가 nil을 반환하는 것을 어떻게 알 수 있습니까? 로깅이나 디버거로 확인 했습니까? – rdelmar