화면에서 스크롤되어 표시되는 데이터를 해제하지 않는 UITableView가 있습니다.dequeueReusableCellWithIdentifier가 데이터를 해제하지 않습니다.
각 표 셀은 이름, 날짜 및 그림을 표시해야합니다. 셀의 첫 번째 화면은 재사용되지 않아 시작시 올바르게 작동합니다. 그러나 스크롤을 시작하고 셀을 다시 사용하면 표시되는 데이터는 이전에 저장 한 셀에 누적됩니다 (예 : 1971 년 12 월 15 일에 날짜가 1981 년 7 월 4 일에 누적 됨).
이- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewCellIdentifier];
self.nameArray = @[@"list of names"];
self.dateArray = @[@"list of dates"];
self.imageArray = @[@"list of images"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.nameArray count];
}
- (UIView *)messageFeed:(NSIndexPath *)indexPath
{
UIView *feedView = [[UIView alloc] init];
//...feedView attributes
UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(..., ..., ..., ...)];
nameLabel.text = self.nameArray[indexPath.row];
//nameLabel attributes
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(..., ..., ..., ...)];
dateLabel.text = self.dateArray[indexPath.row];
//dateLabel attributes
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(..., ..., ..., ...)];
imageView.image = [UIImage imageNamed: self.imageArray[indexPath.row]];
//imageView attributes
[feedView addSubview:nameLabel];
[feedView addSubview:dateLabel];
[feedView addSubview:imageView];
return feedView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCellIdentifier forIndexPath:indexPath];
// Configure the cell...
[cell addSubview:[self messageFeed:indexPath]];
return cell;
}
셀을 처음 추가했을 때마다 셀을 표시/재사용 할 때마다 하위보기가 추가됩니다. 즉, 내용을 바꾸지 않고 (맨 위에 추가하는 것만으로) 이미지가 공개되지 않습니다. 이 주제를 다루는 SO에 대한 많은 질문이 있습니다. Storyboard 또는 XIB에서 IB의 셀을 디자인하는 것이 더 좋지만, cell == nil 인 경우에만 뷰를 추가하거나, 더 나은 방법으로 뷰를 추가하려면 tableView : cellForRowAtIndexPath : 메소드를 다시 고려해야합니다. 검색을 수행하면 필요한 모든 정보를 찾을 수 있습니다. 예 : http://stackoverflow.com/q/16174358/558933 –