以下は、インデックスパスの行のセルの完全なコードです。ここでは、値に基づいて返される複数のカスタムセルとしてのテーブルビューです。テーブルビューをスクロールすると、多くの遅れ..UITableViewのスクロールが複数のカスタムセルでスムーズでない
- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
KVembedLinkTableViewCell* KVCell = [tableView dequeueReusableCellWithIdentifier:@"Link"];
[KVCell flushCell];
[KVCell layoutIfNeeded];
_postDict = [NSMutableDictionary dictionaryWithDictionary:[cardDetailsArray objectAtIndex:indexPath.row]];
NSLog(@"feedstimeline postdict: %@",_postDict);
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
NSArray *embedlist = [NSArray new];
embedlist = [_postDict valueForKeyPath:@"recentpost.embedlist"];
NSArray *medialist = [NSArray new];
medialist = [_postDict valueForKeyPath:@"recentpost.medialist"];
KVCell.embededDetails = _postDict;
KVCell.embedlist = embedlist;
NSString *discription = [NSString stringWithFormat:@"%@",[_postDict valueForKeyPath:@"recentpost.staticdata.contenttext"]];
discription = [CVUtilityManager stripEmptyTags:discription];
KVCell.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCell.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCell.userDescriptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCell laodUserDescription:attr];
[KVCell.userDescription updateConstraints];
[KVCell.userDescription setNeedsLayout];
[KVCell.userDescription layoutIfNeeded];
[KVCell setLikeDelegate:self];
NSString *typeOfCardString = cardTypeArray[indexPath.row];
if ([CVUtilityManager stringIsNull:typeOfCardString]) typeOfCardString = @"UNKNOWN";
_typeOfCard = [self defineCardTypeFromType:typeOfCardString];
switch (_typeOfCard) {
case VIDEO: {
if (embedlist.count > 0) {
if (embedlist[0] != nil) {
[KVCell loadVideoDetails:[NSMutableDictionary dictionaryWithDictionary:embedlist[0]]];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case UNKNOWN:
case TEXT: {
[KVCell loadTextWithString];
KVCell.linkViewHeight.constant = 0;
KVCell.multiTableViewHeight.constant = 0;
[KVCell laodCellContents];
[KVCell.linkContentView layoutIfNeeded];
[KVCell.linkContentView updateConstraints];
[KVCell layoutIfNeeded];
[KVCell setNeedsLayout];
[KVCell updateConstraints];
NSLog(@"card type TEXT");
}break;
case EMBEDFB: {
if (embedlist.count > 0) {
if (embedlist[0] != nil) {
NSString *URLFB = [embedlist[0] objectOrNilForKey:@"url"];
[KVCell loadFaceBookDetails:[CVUtilityManager neutraliseString:URLFB] withVideoButtonStatus:NO];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case EMBEDINSTAGRAM: {
if (embedlist.count > 0) {
if (embedlist[0] != nil) {
NSString *URLINSTA = [embedlist[0] objectOrNilForKey:@"url"];
[KVCell loadInstagramDetails:[CVUtilityManager neutraliseString:URLINSTA]];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case EMBEDPHOTO: {
if (embedlist.count > 0) {
if (embedlist[0] != nil) {
KVCell.linkViewHeight.constant = 253;
[KVCell embedPhoto:[NSMutableDictionary dictionaryWithDictionary:embedlist[0]]];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
KVCell.multiTableViewHeight.constant = 0;
KVCell.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCell.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCell.userDescriptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCell laodUserDescription:attr];
[KVCell.userDescription updateConstraints];
[KVCell.userDescription setNeedsLayout];
[KVCell.userDescription layoutIfNeeded];
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case KANVZPOST:
case LINK: {
if (embedlist.count > 0) {
if (embedlist[0] != nil) {
KVCell.linkViewHeight.constant = 253;
[KVCell loadLinkView:[NSMutableDictionary dictionaryWithDictionary:embedlist[0]]];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
KVCell.multiTableViewHeight.constant = 0;
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case SOUND_CLOUD_AUDIO:
case MULTI_SOUND_CLOUD_AUDIO: {
NSLog(@"card type MULTI_SOUND_CLOUD_AUDIO");
if (embedlist.count > 0) {
[KVCell loadAudioLinksWithArray:embedlist];
KVCell.multiTableViewHeight.constant = embedlist.count * 132.00;
KVCell.linkViewHeight.constant = 0;
}else
KVCell.multiTableViewHeight.constant = 0;
KVCell.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCell.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCell.userDescriptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCell laodUserDescription:attr];
[KVCell.userDescription updateConstraints];
[KVCell.userDescription setNeedsLayout];
[KVCell.userDescription layoutIfNeeded];
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case EMBEDRICH:
case MULTIPLE_LINK: {
if (embedlist.count > 0) {
[KVCell loadMultiLinksWithArray:embedlist];
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case FACEBOOK_VIDEO_CARD: {
if (embedlist.count > 0) {
if (embedlist[0] != nil) {
NSString *URLFB = [embedlist[0] objectOrNilForKey:@"url"];
[KVCell loadFaceBookDetails:[CVUtilityManager neutraliseString:URLFB] withVideoButtonStatus:YES];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case AUDIO: {
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
KVembedAudio
* KVCellAUDIO = [tableView dequeueReusableCellWithIdentifier:@"Audio" forIndexPath:indexPath];
KVCellAUDIO.embededDetails = _postDict;
[KVCellAUDIO setLikeDelegate:self];
KVCellAUDIO.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCellAUDIO.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCellAUDIO.userDescrptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCellAUDIO laodUserDescription:attr];
[KVCellAUDIO.userDescription updateConstraints];
[KVCellAUDIO.userDescription setNeedsLayout];
[KVCellAUDIO.userDescription layoutIfNeeded];
[KVCellAUDIO performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:true];
[KVCellAUDIO.contentView layoutIfNeeded];
NSLog(@"card type AUDIO");
return KVCellAUDIO;
} break;
case PHOTO: {
KVCell.embedlist = medialist;
if (medialist.count > 0) {
if (medialist[0] != nil) {
[KVCell uploadPhoto:[NSMutableDictionary dictionaryWithDictionary:medialist[0]]];
}else
KVCell.linkViewHeight.constant = 0;
}else
KVCell.linkViewHeight.constant = 0;
KVCell.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCell.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCell.userDescriptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCell laodUserDescription:attr];
[KVCell.userDescription updateConstraints];
[KVCell.userDescription setNeedsLayout];
[KVCell.userDescription layoutIfNeeded];
[KVCell performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
} break;
case MULTIPLE_EMBEDPHOTO: {
NSLog(@"card type MULTIPLE_EMBEDPHOTO");
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
NSArray *mediaList = [[_postDict objectOrNilForKey:@"recentpost"] objectOrNilForKey:@"embedlist"];
KVembedPhotoMultiple
* KVCellPhoto = [tableView dequeueReusableCellWithIdentifier:@"Photo Multiple" forIndexPath:indexPath];
[KVCellPhoto flushCell];
KVCellPhoto.embededDetails = _postDict;
if (mediaList.count>0) {
[KVCellPhoto loadEmbedPhotos:mediaList];
}
[KVCellPhoto setLikeDelegate:self];
KVCellPhoto.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCellPhoto.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCellPhoto.userDescrptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCellPhoto laodUserDescription:attr];
[KVCellPhoto.userDescription updateConstraints];
[KVCellPhoto.userDescription setNeedsLayout];
[KVCellPhoto.userDescription layoutIfNeeded];
[KVCellPhoto performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
[KVCellPhoto.contentView layoutIfNeeded];
return KVCellPhoto;
} break;
case MULTIPLE_PHOTO: {
NSLog(@"card type MULTIPLE_PHOTO");
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
NSArray *mediaList = [[_postDict objectOrNilForKey:@"recentpost"] objectOrNilForKey:@"medialist"];
NSLog(@"mediaList %@",mediaList);
KVembedPhotoMultiple
* KVCellPhoto = (KVembedPhotoMultiple *)[tableView dequeueReusableCellWithIdentifier:@"Photo Multiple" forIndexPath:indexPath];
[KVCellPhoto flushCell];
KVCellPhoto.embededDetails = _postDict;
if (mediaList.count>0) {
[KVCellPhoto loadUploadedPhotos:mediaList];
}
[KVCellPhoto setLikeDelegate:self];
KVCellPhoto.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCellPhoto.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCellPhoto.userDescrptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCellPhoto laodUserDescription:attr];
[KVCellPhoto.userDescription updateConstraints];
[KVCellPhoto.userDescription setNeedsLayout];
[KVCellPhoto.userDescription layoutIfNeeded];
[KVCellPhoto performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
[KVCellPhoto.contentView layoutIfNeeded];
return KVCellPhoto;
} break;
case EMBED_MUL_VIDEO: {
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
KVembedVideoMultipleTableViewCell
* KVCellVideo = [tableView dequeueReusableCellWithIdentifier:@"Video Multiple" forIndexPath:indexPath];
KVCellVideo.embededDetails = _postDict;
[KVCellVideo setLikeDelegate:self];
[KVCellVideo performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
[KVCellVideo.contentView layoutIfNeeded];
NSLog(@"card type EMBED_MUL_VIDEO");
return KVCellVideo;
} break;
case EMBEDTWEET:
case EMBED_MUL_TWEET: {
NSLog(@"card type EMBED_MUL_TWEET");
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
KVembedTweetMultiple* KVCellTweet = [tableView dequeueReusableCellWithIdentifier:@"Tweet Multiple" forIndexPath:indexPath];
[KVCellTweet setLikeDelegate:self];
KVCellTweet.embededDetails = _postDict;
KVCellTweet.embedlist = embedlist;
[KVCellTweet.userDescription setText:discription];
KVCellTweet.userDescriptionHeight.constant = [CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCellTweet laodUserDescription:attr];
[KVCellTweet.userDescription updateConstraints];
[KVCellTweet.userDescription layoutIfNeeded];
[KVCellTweet loadTweets];
[KVCellTweet performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:TRUE];
[KVCellTweet.contentView updateConstraints];
[KVCellTweet.contentView layoutIfNeeded];
[KVCellTweet layoutIfNeeded];
[KVCellTweet updateConstraints];
return KVCellTweet;
} break;
case EMBED_MUL_AUDIO: {
NSLog(@"card type EMBED_MUL_AUDIO");
[_postDict setObject:indexPath forKey:KEY_INDEXPATH];
KVembedMultiAudio* KVCellAudio = (KVembedMultiAudio*)[tableView dequeueReusableCellWithIdentifier:@"EmbedMultiAudio" forIndexPath:indexPath];
KVCellAudio.embededDetails = _postDict;
[KVCellAudio setLikeDelegate:self];
KVCellAudio.userDescription.preferredMaxLayoutWidth = _timeLineTableView.bounds.size.width -16;
[KVCellAudio.userDescription setText:discription];
NSAttributedString *attr = [CVUtilityManager UserDescription:discription];
KVCellAudio.userDescrptionHeight.constant =[CVUtilityManager sizeForLabel:KVCell.userDescription withAttributedString:attr];
[KVCellAudio laodUserDescription:attr];
[KVCellAudio.userDescription updateConstraints];
[KVCellAudio.userDescription setNeedsLayout];
[KVCellAudio.userDescription layoutIfNeeded];
[KVCellAudio performSelector:@selector(laodCellContents) onThread:[NSThread mainThread] withObject:nil waitUntilDone:true];
[KVCellAudio.contentView layoutIfNeeded];
return KVCellAudio;
}
break;
default:
break;
}
[KVCell updateConstraints];
[KVCell layoutIfNeeded];
return KVCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSNumber *height = [self.heightAtIndexPath objectForKey:indexPath];
if(height) {
return height.floatValue;
} else {
return UITableViewAutomaticDimension;
}
}
Webサービスの呼び出しと画像のダウンロードをバックグラウンドスレッドに移動すると、テーブルビューがスムーズにスクロールします – Vinodh
tableView:cellForRowAtIndexPath:メソッドには多くの問題があります。できるだけ早くセルを返すべきです。この記事は参考になるでしょうhttps://medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5#.v9pdjnqga –
@OstapHorbachありがとう..しかし、データを設定する場所私のセル..私は複数のカスタムセルを使用しているので - 私はwilldisplayセルメソッド内のデータを設定することはできません..任意の提案 – PunithBm