2013-05-14 2 views
0

나는 여러 행의 데이터를 표시하기 위해 이름 : textLabel.text, 상태 (온라인/오프라인)를 표시하는 imageView, 추가 정보를위한 detailTextLabel을 사용하고 있습니다.업데이트 UITableView의 imageView/detailTextLabel

ex. 내가 다른 함수에서 imageView.image 및 detailTextLabel.text를 업데이트 할 수있는 방법

cell.imageView.image = [UIImage imageNamed:@"checking.png"]; 
cell.textLabel.text = @"NAME"; 
cell.detailTextLabel.text = @"Checking..."; 

cellForRowAtIndexPath

있다. UITableView 메서드가 있습니까? 셀을 대상으로 IndexPath 행을 사용해야 할 것으로 추측됩니다. 각 imageView 및 detailTextLabel에 태그를 지정 하시겠습니까?

감사합니다.

답변

0

더 나은 옵션은 모델의 데이터를 업데이트 한 다음 테이블보기를 reloadData (또는 업데이트 된 행을 구체적으로 알고있는 경우 reloadRowsAtIndexPaths:withRowAnimation:)으로 요청하는 것이 좋습니다.

이것은 데이터 모델의 무결성을 유지하며보기를 관리하는 가장 간단한 코드입니다.

+0

행 (IndexPath.row)을 열고 detailTextLabel 및 imageView.image를 업데이트 하시겠습니까? 몇 가지 샘플 코드를 제공 할 수 있습니까? 감사. – ialphan

+0

테이블 뷰 데이터 원본 메서드를 올바르게 구현하고 있습니까? tableView : cellForRowAtIndexPath : – Wain

+0

예, 다음과 같은 것을 사용했습니다. UITableViewCell * cell0 = [self.tableView cellForRowAtIndexPath : [NSIndexPath indexPathForRow : 0 inSection : 0]]; indexPathForRow 및 inSection이 고정되는 위치. Frm이 cell0을 업데이트 할 수있었습니다. cell0.imageView.image = [UIImage imageNamed : @ "connected.png"]; – ialphan

0

이 같은 속성을 사용하려고한다 : 당신이 그랬던 것처럼

@property (nonatomic, strong) UIImage *image; 
@property (nonatomic, strong) NSString *textLabel; 
@property (nonatomic, strong) NSString *detailTextLabel; 

그럼 당신은 당신의 셀에이 속성을 추가 : 당신은 당신의 데이터를 업데이트 할 때마다

cell.imageView.image = image; 
cell.textLabel.text = textLabel; 
cell.detailTextLabel.text = detailTextLabel; 

, 당신은 메소드를 호출하는 다시로드하려는 셀의 indexPath가 포함 된 배열을 사용하여 셀을 다시로드하십시오.

[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone]; 
+0

또한 작동하지 않습니다 : [self.tableView beginUpdates]; \t detailTextLabel1 = @ "새로운 세부 텍스트"; \t [self.tableView reloadRowsAtIndexPaths : [NSArray arrayWithObject : [NSIndexPath indexPathForRow : 0 inSection : 0]] withRowAnimation : UITableViewRowAnimationFade]; \t [self.tableView endUpdates]; \t [self.tableView reloadData]; – ialphan