Search code examples
iosjsonxcodeuitableviewcell

I have paste some error with paste text in UILabel


I have some problem with my created UILabel in tableViewCell. So i have tableView with Textlabel, detail text and my third created label to cell. So i get info from JSON and paste to this third label so its result:

enter image description here

But when i try to scroll my table i have some problem with time text:

enter image description here

So when i added UIColor white color for background to this label i have not this idiot behind number. Help please what i doing wrong?

i add my code tableView

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



    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];




    if(! cell)
    {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];

               cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];

    }

    cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"song"];

    cell.detailTextLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"artist"];

    UILabel *mainLabel;

    //frame=CGRectMake(Позиция по X, Позиция по Y, Размеры ширина, Раздел высота)

    mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 58, 220.0, 15.0)] autorelease];

    mainLabel.font = [UIFont systemFontOfSize:14.0];

    mainLabel.textColor = [UIColor blackColor];
    [cell.contentView addSubview:mainLabel];

    mainLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"start"];

    [cell.imageView setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:indexPath.row] objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"[email protected]"]];



    cell.textLabel.textColor = [UIColor whiteColor];

    cell.detailTextLabel.textColor = [UIColor whiteColor];

    mainLabel.backgroundColor = [UIColor clearColor];

    mainLabel.textColor = [UIColor whiteColor];

    [tableTrack setBackgroundView:nil];

    [TrackTableView setBackgroundView:nil];

    tableTrack.backgroundColor = [UIColor clearColor];

    TrackTableView.backgroundColor = [UIColor clearColor];

    UIFont *f = [UIFont fontWithName:@"Helvetica 35 Thin" size:18.0f];

    cell.textLabel.font = f;

    UIFont *f2 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];

    cell.detailTextLabel.font = f2;

    UIFont *f3 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];

    mainLabel.font = f3;


    self.tableTrack.separatorStyle = UITableViewCellSeparatorStyleNone;

    UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(10, 74, 1024, 1)];
    separatorView.layer.borderColor = [UIColor whiteColor].CGColor;
    separatorView.layer.borderWidth = 0.5;
    [cell.contentView addSubview:separatorView];

    self.TrackTableView.separatorStyle = UITableViewCellSeparatorStyleNone;





    return cell;
}

Solution

  • just try this delegate method.. the problem is you are adding labels to dequeed cell only addsubview in when they are created...try this code..

      -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
    
    
    
            static NSString *CellIdentifier = @"Cell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
    
    
    
    
             if(! cell)
                {
                    cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
    
    
             mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 58, 220.0, 15.0)] autorelease];
    
                mainLabel.font = [UIFont systemFontOfSize:14.0];
    
                mainLabel.textColor = [UIColor blackColor];
                [cell.contentView addSubview:mainLabel];
    
            UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(10, 74, 1024, 1)];
                separatorView.layer.borderColor = [UIColor whiteColor].CGColor;
                separatorView.layer.borderWidth = 0.5;
                [cell.contentView addSubview:separatorView];
                }
    
                cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"song"];
    
                cell.detailTextLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"artist"];
    
                UILabel *mainLabel;
    
                //frame=CGRectMake(Позиция по X, Позиция по Y, Размеры ширина, Раздел высота)
    
    
                mainLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"start"];
    
                [cell.imageView setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:indexPath.row] objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"[email protected]"]];
    
    
    
                cell.textLabel.textColor = [UIColor whiteColor];
    
                cell.detailTextLabel.textColor = [UIColor whiteColor];
    
                mainLabel.backgroundColor = [UIColor clearColor];
    
                mainLabel.textColor = [UIColor whiteColor];
    
                [tableTrack setBackgroundView:nil];
    
                [TrackTableView setBackgroundView:nil];
    
                tableTrack.backgroundColor = [UIColor clearColor];
    
                TrackTableView.backgroundColor = [UIColor clearColor];
    
                UIFont *f = [UIFont fontWithName:@"Helvetica 35 Thin" size:18.0f];
    
                cell.textLabel.font = f;
    
                UIFont *f2 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];
    
                cell.detailTextLabel.font = f2;
    
                UIFont *f3 = [UIFont fontWithName:@"Helvetica 35 Thin" size:14.0f];
    
                mainLabel.font = f3;
    
    
                self.tableTrack.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    
                self.TrackTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    
    
    
                return cell;
            }