2013-10-25 6 views
0

tableViewCell에 작성한 UILabel에 문제가 있습니다. 그래서 TextLabel, 세부 텍스트 및 cell에 세 번째로 생성 된 레이블이있는 tableView가 있습니다. 그래서 내가 JSON에서 정보를 얻을이 세 번째 레이블 그래서 그 결과를 붙여 넣습니다UILabel에 텍스트를 붙여 넣을 때 오류가 발생했습니다.

enter image description here

을하지만 난 내 테이블을 스크롤 할 때 나는 시간 텍스트 몇 가지 문제가 있습니다

enter image description here

을 그래서이 라벨에 배경색으로 UIColor 흰색을 추가했을 때 숫자 뒤에이 멍청이가 없습니다. 내가 뭘 잘못했는지 도와 줘?

가 나는 경우 조건의 경우 (셀 == 전무) 이외의 실수는 당신이 (다른 부분)에 라벨을 할당 한되어

-(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; 
} 
+0

데이터 소스 위임 방법을 제공하시기 바랍니다 ..이 코드를 시도! – Raon

+0

내 코드 프로젝트를보고 싶습니까? – Genevios

+0

아니요 cellForRowatIndexPath 대리자 메서드 만 – Raon

답변

1

그냥 .. 문제 만 만들어 질 때의 addsubview 셀을 dequeed하는 라벨을 추가한다이 위임 방법을 시도 ...

-(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; 
     } 
0

내 코드를 tableView 추가합니다. 셀을 처음 만들 때 레이블을 한 번만 만들어야합니다.

코드를 실행할 때 컨트롤은 셀이 nil인지 값이 있는지 확인합니다. 매번 다른 부분에 레이블을 할당하는 경우 (스크롤하는 동안) 매번 새 레이블을 작성합니다. if 조건에 할당하면 라벨은 각 셀에 한 번만 할당되며 스크롤 할 때 텍스트 값을 업데이트합니다.

+0

내 상황이 어떻게 바뀌나요? 나 한테 도움이된다면? – Genevios

관련 문제