개체로 채워진 UITableView가 있습니다. didSelectRowAtIndexPath 메서드에서 행을 선택하면 UITableViewCellAccessoryCheckmark가 나타나고 선택하지 않으면 사라집니다.스크롤 할 때 UITableViewCellAccessory가 사라진다 화면
을 heres didSelectRowAtIndexPath 메서드에 대한 코드 :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *curCell = [beerTable cellForRowAtIndexPath:indexPath];
if (curCell.accessoryType == UITableViewCellAccessoryCheckmark) {
[curCell setAccessoryType:UITableViewCellAccessoryNone];
compareCount = (compareCount - 1);
if (tableView == [[self searchDisplayController] searchResultsTableView]) {
NSString *objBeer = [searchResults objectAtIndex:indexPath.row];
[compareBeers removeObject:[searchResults objectAtIndex:indexPath.row]];
[compareCarbs removeObject:[carbAmount objectAtIndex:[beerNames indexOfObject:objBeer]]];
}
else {
[compareBeers removeObject:[beerNames objectAtIndex:indexPath.row]];
[compareCarbs removeObject:[carbAmount objectAtIndex:indexPath.row]];
}
}
else {
[curCell setAccessoryType:UITableViewCellAccessoryCheckmark];
compareCount = (compareCount + 1);
if (tableView == [[self searchDisplayController] searchResultsTableView]) {
NSString *objBeer = [searchResults objectAtIndex:indexPath.row];
[compareBeers addObject:[searchResults objectAtIndex:indexPath.row]];
[compareCarbs addObject:[carbAmount objectAtIndex:[beerNames indexOfObject:objBeer]]];
}
else {
[compareBeers addObject:[beerNames objectAtIndex:indexPath.row]];
[compareCarbs addObject:[carbAmount objectAtIndex:indexPath.row]];
}
}
if (compareCount > 0) {
if (compareOn == YES){
}
else {
compareButton.enabled = YES;
UIImage *image = [UIImage imageNamed:@"redbutton.png"];
[compareButton setImage:image];
}
}
else {
compareButton.enabled = NO;
[compareButton setImage:nil];
[compareButton setCustomView:nil];
}
}
가 나는 또한 내 cellForIndexPath로 이것을 가지고가 :
이- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
// Setting separate tables correctly....
return cell;
}
가 내 문제가 선택된 셀이 스크롤된다 보지 못했을 때 다시 볼 때 그 값과 관련된 체크 표시가 사라졌습니다.
체크 표시가 사라지지 않게하려면 어떻게해야합니까? 당신이 스크롤 할 때
감사
사용자가 탭을 사용하여 행을 선택하면 cellForRowAtIndexPath에 체크 표시를 설정할 수 있습니까? 어떤 종류의 예를 들어 보겠습니까? –
체크 표시를 설정하기 위해 행을 탭하면 해당 정보를 모델 또는 컨트롤러 자체에 저장해야합니다. 사용자가 행을 클릭 할 때 색인 경로로 사전에 검사 된 상태를 저장 한 다음 해당 값을 사용하여 cellForRowAtIndexPath에서 검사 된 상태를 설정하는 것과 같이 간단한 작업을 수행 할 수 있습니다. –