내 문제와 비슷한 게시물을 찾았지만 동일하지는 않습니다.uitableviewcell에서 tableview 중복 행
내 앱에서 사용자는 여러 가지보기를 탐색하여 원하는 결과를 자세히 볼 수 있습니다. 사용자가 앞으로 나아갈 때, 뒤로, 앞으로 갈 때 등 행이 다시 그려지고 다시 쓰여지고 텍스트가 더 강하고 굵게 표시됩니다.
나는 게시물 중 일부에서 이것은 행을 만드는 방법과 관련이 있으며, cellforrowatindexpath
메서드 내에서 사용할 수있는 것을 발견했다.
사용자가 테이블 뷰간에 앞뒤로 이동할 때마다 행이 다시 채워지거나 다시 그려지지 않도록해야 할 일이 있습니까? 아래 코드에 뭔가를 추가하거나 viewwillappear 메서드에 무언가를 추가해야합니까 (현재 테이블의 뷰에 'reloaddata'가 있지만 도움이되지 않습니다)?
[cell.contentView addSubview:label];
당신은 새로운 세포의 여부 테이블 셀에 하위 뷰를 추가 : 때문에이 라인에
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *label = [[[UILabel alloc] init] autorelease];
label.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];
label.frame = CGRectMake(10.0f, 10.0f, 220.0f, 22.0f);
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.text = [mapareaArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:label];
CustomCellBackgroundView *bgView = [[CustomCellBackgroundView alloc] initWithFrame:CGRectZero];
bgView.borderColor = [UIColor clearColor];
bgView.fillColor = [UIColor whiteColor];
bgView.position = CustomCellBackgroundViewPositionSingle;
cell.backgroundView = bgView;
return cell;
}
고맙습니다. 큰 도움. 이것에 관한 마지막 질문 하나 - 프로그래밍 배경이 없으므로 헤더 파일에서 #define을 사용하여 무슨 뜻인지 확실치 않습니다. 이 작업을 수행하는 구문은 무엇입니까? 나는 전에 그것을 보았고 헤더에 '#define kMyTag'를 넣으려고했으나 이것이 작동하지 않습니다 ...나는 당신이 kMyTag를 값으로 정의 할 필요가 있다고 가정하고 있지만 어떤 구문이 이것을 할 것인지 확신 할 수 없다. 도울 수 있니? – SKayser