iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 表视图单元重新加载第一个单元格内容大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_673_2@
这就是我的表格填充方式:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath {

    CellNewsInfo *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {

        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:@"cell"];
    }
    // Set up the cell
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    NSString *titleArticle=[[stories objectATindex: storyIndex] objectForKey: @"title"];
  titleArticle = [titleArticle StringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if (indexPath.row==0) {
        scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0,320,200)];
        scr.tag = 1;
        scr.autoresizingMask=UIViewAutoresizingNone;
        [cell addSubview:scr];
        [self setupScrollView:scr];
        UIPageControl *pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(120,170,80,36)];
        [pgCtr setTag:12];
        pgCtr.BACkgroundColor = [UIColor clearColor];
        pgCtr.numberOfPages=5;
        pgCtr.TintColor=[UIColor redColor];
        pgCtr.pageInDicatorTintColor=[UIColor blueColor];
        self.pageControl.hidden=YES;
        pgCtr.currentPageInDicatorTintColor = [UIColor redColor];
        pgCtr.autoresizingMask=UIViewAutoresizingNone;
        [cell addSubview:pgCtr];
    }
    else{
    cell.title.text=titleArticle;
    cell.title.numberOfLines=2;

为什么当我滚动它时,第一个单元格正在重新加载?我只想在初学者那里只有一次滚动视图.

@H_673_2@

解决方法

再次添加scrollview的原因是,一旦取消分配单元格,它们将被重用.

如果要在一个tableView中显示多个单元格类型,或者甚至使用两个不同的单元格标识符(取决于行是否为0),则应该虑创建自己的自定义单元格.

CellNewsInfo *cell;
if (indexPath.row == 0) {
    cell = [tableView dequeueReusableCellWithIdentifier:@"scrollCell" forIndexPath:indexPath];

    if ([cell viewWithTag:1]) {
        scr = [cell viewWithTag:1];
    }
    else {
        scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0,200)];
        scr.tag = 1;
    }
    // conTinue customization here with scrollview
}
else {
    cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    // conTinue customization here without scroll view
}

return cell;
@H_673_2@ @H_673_2@
@H_673_2@
@H_673_2@

大佬总结

以上是大佬教程为你收集整理的ios – 表视图单元重新加载第一个单元格内容全部内容,希望文章能够帮你解决ios – 表视图单元重新加载第一个单元格内容所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。