-1
친구들, 내 nsarray에서로드하는 tableview가 있지만 셀을 관리 한 후에 잘못된 위치에 요소가 표시됩니다. 생성 세포 :uitableview에서 행을 삭제하고 추가합니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *currentArray = [comments objectAtIndex:indexPath.section];
NSDictionary *currentComment = (NSDictionary *)[currentArray objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"TitleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
int commentLevel = [[currentComment objectForKey:@"level"] intValue];
NSString *commentText = [currentComment objectForKey:@"text"];
cell.textLabel.tag = 0xff ;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:17.0];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.text = commentText;
cell.textLabel.backgroundColor = [UIColor clearColor];
if (commentLevel > 0 && cell.imageView.image == nil) {
cell.imageView.image = [UIImage imageNamed:@"06-arrow-northwest.png"];
}
if (commentLevel == 0 && [[openedSections objectAtIndex:indexPath.section] boolValue] == NO) {
if ([currentArray count] > 1) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
return cell;
}
편집 방법 :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([[openedSections objectAtIndex:indexPath.section] boolValue] == NO) {
[openedSections replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithInt:1]];
NSMutableArray *rows = [[NSMutableArray alloc] init];
int i = 1;
while (i < [[comments objectAtIndex:indexPath.section] count]) {
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:indexPath.section];
[rows addObject:[path copy]];
[path release];
i = i + 1;
}
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
[rows release];
} else if (indexPath.row == 0) {
[openedSections replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithInt:0]];
NSMutableArray *rows = [[NSMutableArray alloc] init];
int i = 1;
while (i < [[comments objectAtIndex:indexPath.section] count]) {
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:indexPath.section];
[rows addObject:[path copy]];
[path release];
i = i + 1;
}
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
[rows release];
}
}
당신에게 어떤 아이디어가 있습니까?
해결 방법이 아닙니다. NSArray "comments"는 모든 셀에 대한 NSDictionaries를 포함하는 NSArrays를 포함합니다. 그러나 nsarray "openedSections"는 그것을 제어합니다. – werbary