2014-10-21 1 views
1

사용자 정의 UItableViewcell을 사용하여 데이터를 표시해야하는 응용 프로그램을 개발 중입니다. UItableViewCell에 데이터를 표시하는 동안 UItableViewCell에서 콘텐츠 (이전에 UItableViewCell에 이미 콘텐츠가 있거나 일부 데이터로 바인딩되어 있음)가 있으면이를 삭제하고 새 데이터로 바인딩해야합니다. 그렇지 않으면 데이터를 tableview에 바인딩해야합니다. 아래는 우리가 시도한 코드입니다.새 데이터로 UItableViewcell을 새로 고치는 방법

if (cell.thumbnailImageView.image==nil) {    
     cell.thumbnailImageView.image = [imagearray objectAtIndex:indexPath.row]; 
     // cell.pricelabel.text = [pricearray objectAtIndex:indexPath.row]; 
     cell.DealDecLabel.text=[DealDecarray objectAtIndex:indexPath.row]; 

     cell.pricelabel.text = [NSString stringWithFormat:@"%@",[pricearray objectAtIndex:indexPath.row]]; 
    } 
    else 
    { 
     cell.thumbnailImageView.image=nil; 
     cell.DealDecLabel.text=nil; 
     cell.pricelabel.text=nil; 

     cell.thumbnailImageView.image = [imagearray objectAtIndex:indexPath.row]; 
     // cell.pricelabel.text = [pricearray objectAtIndex:indexPath.row]; 
     cell.DealDecLabel.text=[DealDecarray objectAtIndex:indexPath.row]; 

     cell.pricelabel.text = [NSString stringWithFormat:@"%@",[pricearray objectAtIndex:indexPath.row]]; 
    } 

누구나 해결책이나 코드를 제공하는 사람은 대단히 감사합니다.

답변

2

이 코드는 cellForRowAtIndexPath에 있습니다. 그것을 할 필요가 있지만, 가정은

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
          withRowAnimation:UITableViewRowAnimationNone]; 

당신이 실제로 필요하지 않은 모든 일을 다시로드하는있는 tableView

[self.tableView reloadData]; 

의 특정 셀을 다시로드하지 않다면 매번 이미지를 없애려면 ... 간단하게 할 수 있습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    MYCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (!cell) 
     cell = [[MYCustomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

    cell.thumbnailImageView.image = [imagearray objectAtIndex:indexPath.row]; 
    cell.DealDecLabel.text=[DealDecarray objectAtIndex:indexPath.row]; 
    cell.pricelabel.text = [NSString stringWithFormat:@"%@",[pricearray objectAtIndex:indexPath.row]]; 


    return cell; 

} 

P otentially

cell.imageView, cell.textLabelcell.detailTextLabelUITableViewCell 서브 클래스에서 제공되는 고려 .. 사전이 아니라 3 개 별도의 배열의 배열을보고, 나는 아마 그들이 그들을 당신의 두 개의 레이블과 같이 삭제하는 사람들을 편집 할 것 불필요한. detailTextLabel는, DealDecarray 당신 배열 즉에 새로운 데이터를 추가 단지

[self.tableView reloadData]; 

그것은 당신을 위해 작동 호출 할 때마다 UITableViewCellStyleDefaultUITableViewCellStyleSubtitle

0

로 변경해야합니다.

1

웹 서비스에서 데이터를 가져 오는 경우 아래 코드를 추가하십시오.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"Did Finished loading...."); 
    // down here reload your tableview 
    [self.tableView reloadData]; 
} 
+0

우리는 다른 tableview 셀을 기반으로 데이터를 가져오고 그 다음에 데이터를 다른 tableview에 바인딩합니다. –

0

uitableview의 데이터 소스를 새 데이터로 변경 한 다음 테이블을 다시로드하십시오.

[테이블 reloadData];

+0

우리는 다른 tableview 셀을 기반으로 데이터를 가져오고 있습니다. 그런 다음 데이터를 다른 tableview에 바인딩합니다. –

+0

하나의 tableviewcell을 클릭하면 해당 시간에 didselectrowatindex 메소드 호출이 다른 테이블의 데이터 소스를 변경합니다. –

관련 문제