に設定された値は持っていない:私は私のUITableView内の行をタップしたときに、私は、ログに出力する1と0の交互の値を、これを期待してい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;
}
}
を。それに対応して、私がタップする行を展開して折り畳む。
何らかの理由で、NSDictionaryにキーと値のペアが存在しないため、結果として行が拡大することはありません。 heightForRowメソッドからのログのように出てくる:私は間違って何をやっている
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)
:
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方法からロギングはとして出てきますか?
NSMutableDictionaryにしてください – Stavash
私のコードではNSMutableDictionaryです - コメントの入力ミスです –
できますか? didSelect ..とheightFor ..メソッドのNSLogを区別しますか? – Ilanchezhian