gpt4 book ai didi

ios - 由于方法调用,Tableview 滚动速度变慢

转载 作者:行者123 更新时间:2023-11-29 02:43:38 25 4
gpt4 key购买 nike

在我的表格 View 单元格中,有一个描述标签。描述文本将通过单独方法中的属性文本突出显示。此方法是从 cellforRowIndexPath 调用的,这就是 tableview 滚动滞后很多的原因。

我的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SearchVCCell *cell = (SearchVCCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SearchVCCell" owner:self options:nil];
cell = [nib objectAtIndex:0];

cell.lbl_title.text=[NSString stringWithFormat:@"%@",[arrTitle objectAtIndex:indexPath.row]];
cell.lbl_disc.text=[NSString stringWithFormat:@"%@",[arrDescription objectAtIndex:indexPath.row]];
cell.lbl_page.text=[NSString stringWithFormat:@"Page: %d",[[arrPageNumber objectAtIndex:indexPath.row]intValue]];


int p= [self highlightText:_search_bar.text :cell.lbl_disc]; //Method Call
cell.lbl_count.text=[NSString stringWithFormat:@"%d",p];
}
return cell;
}

高文本方法:

-(int) highlightText :(NSString *)srcTxt :(UILabel*)txtView {
int srcTxtLen = srcTxt.length;
int idx = 0,count=0;
while (idx<(txtView.text.length-srcTxtLen)) {
NSRange srcRange = NSMakeRange(idx, srcTxtLen);
if ([[txtView.text substringWithRange:srcRange] isEqualToString:srcTxt]) {
NSMutableAttributedString *tmpAttrTxt = [[NSMutableAttributedString alloc] initWithAttributedString:txtView.attributedText];
[tmpAttrTxt addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:srcRange];
txtView.attributedText = tmpAttrTxt;
idx += srcTxtLen;
count++;
} else {
idx++;
}
}
return count;
}

帮我解决一下,提前致谢

最佳答案

你可以用这个替换你的方法调用

NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:cell.lbl_disc.text];
NSRange range=[cell.lbl_disc.text rangeOfString:_search_bar.text];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:range];
[self.textToSpeak setAttributedText:string];

关于ios - 由于方法调用,Tableview 滚动速度变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25419736/

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