UITableViewCell - overlapping with previous cells contents

后端 未结 5 1459
名媛妹妹
名媛妹妹 2021-02-08 15:22

I have this wierd problem with my table

  1. i Have about 20 cells to display
  2. Each cell is about 84px in height
  3. When i click no the cell, i have set a
5条回答
  •  北恋
    北恋 (楼主)
    2021-02-08 15:31

    I know this is a bit late, but I had a similar issue where UILabels created for a cell were still part of the cell when it was reused. So each successive update of the tableview created another UILabel on top of the existing one. I moved the creation of the Labels into the if condition as below and it resolved my issue. Hope it helps someone else. Also note no release as I am using ARC.

        static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) 
    
        {
    
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
        cityText = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
        cityText.font = [UIFont fontWithName:@"Arial" size:20];
        cityText.textAlignment = UITextAlignmentLeft; 
        cityText.backgroundColor = [UIColor clearColor];
    
        regionText = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 100, 20)];
        regionText.font = [UIFont fontWithName:@"Arial" size:20];
        regionText.textAlignment = UITextAlignmentLeft; 
        regionText.backgroundColor = [UIColor clearColor];
    
        }
    

提交回复
热议问题