나는 다음과 같은 코드가 있습니다NSMutableDictionary 가지고 있지 값
//in .h file: NSMutableDictionary* expandedSections;
//in Init method: expandedSections = [[NSMutableDictionary alloc] init];
- (void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSString* key = [NSString stringWithFormat:@"%d", indexPath.row];
NSLog(@"Key: %@", key);
if ([expandedSections objectForKey:key] == nil)
{
NSLog(@"Value Should be: %@", [NSNumber numberWithBool:YES]);
[expandedSections setObject:[NSNumber numberWithBool:YES] forKey:key];
}
else
{
[expandedSections setObject:[NSNumber numberWithBool:![[expandedSections objectForKey:key] boolValue]] forKey:key];
}
NSLog(@"Value: %@", [expandedSections objectForKey:key]);
[tableView beginUpdates];
[tableView endUpdates];
}
- (float) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* key = [NSString stringWithFormat:@"%d", indexPath.row];
NSLog(@"Key: %@", key);
NSLog(@"Value: %@", [expandedSections objectForKey:key]);
if ([expandedSections objectForKey:key] == nil || ![[expandedSections objectForKey:key] boolValue])
{
return 44;
}
else
{
return 88;
}
}
내가 내 jQuery과의 행을 누를 때 교류 1의 값이 0 로그 출력이 기대 해요을 . 그리고 이에 따라 내가 탭하는 행을 확장하고 접습니다.
어떤 이유로 NSDictionary에는 키/값 쌍이 없으므로 결과적으로 행이 확장되지 않습니다. heightForRow 방법에서 로깅과 같이 나온다 :
2012-02-08 11:36:30.291 MappApp[5040:707] Key: 0
2012-02-08 11:36:30.293 MappApp[5040:707] Value: (null)
didSlectRowAt 방법에서 로깅과 같이 나온다 : 내가 잘못 뭐하는 거지
2012-02-08 11:36:44.551 MappApp[5040:707] Key: 0
2012-02-08 11:36:46.530 MappApp[5040:707] Value Should be: 1
2012-02-08 11:36:50.723 MappApp[5040:707] Value: (null)
?
NSMutableDictionary로 변경하십시오. – Stavash
내 코드에 NSMutableDictionary입니다. 주석에 오타가있었습니다. –
Can Pl. didSelect .. 및 heightFor .. 메소드에서 NSLog를 구별 할 수 있습니까? – Ilanchezhian