簡體   English   中英

表視圖單元重新加載第一個單元格內容

[英]Table view cell reload first cell content

這就是我的表格填充方式:

- (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, 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;

為什么當我滾動它時,第一個單元格正在重新加載? 我只想在初學者那里只有一次滾動視圖。

再次添加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, 0, 320, 200)];
        scr.tag = 1;
    }
    // continue customization here with scrollview
}
else {
    cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    // continue customization here without scroll view
}

return cell;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM