わからないメモ2

昨日のメモはヘッダファイルに宣言を書くことで解決しました。
そこで、昨日のメソッドに手を加えてプログラムしたが、今度はポインタ系でミスっているのかうまく動かない。。

データ用JSON

{"fuji11":[{"day":"29日","stage":"green stage","artist":"css"},
			{"day":"30日","stage":"unknown","artist":"cold play"},
			{"day":"31日","stage":"unknown","artist":"cold play"}]}

ルートのロード時処理

- (void)viewDidLoad {
    [super viewDidLoad];
	NSMutableDictionary *readDays =  [NSMutableDictionary dictionary];
	NSError *error;
	NSString *path = [[NSBundle mainBundle] pathForResource:@"fuji11" ofType:@"txt"];
	NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
	NSDictionary *jsonItem = [str JSONValue];
	NSLog(@"%@",jsonItem);
	NSArray *value = [jsonItem objectForKey:@"fuji11"];
	for(NSDictionary *artistInfo in value){
		id day = [artistInfo objectForKey:@"day"];
		NSDictionary *dayStage;
		dayStage = [self getDictonaryForKey:readDays key:day];
		id stageStr = [artistInfo objectForKey:@"stage"];
		NSArray	*stage;
		stage = [self getArrayForKey:dayStage key:stageStr];
		id artist = [artistInfo objectForKey:@"artist"];
		[stage addObject:artist];
	}
	NSLog(@"%@",readDays);
	fujidays = [NSDictionary dictionaryWithObjects:[ readDays allValues] forKeys:[readDays allKeys]];

- (NSDictionary *) getDictonaryForKey:(NSDictionary*)dic key:(NSString *)keyStr{
	id dicReaf = [dic objectForKey:keyStr];
	if(dicReaf == nil){
		dicReaf = [NSMutableDictionary dictionary];
		[dic setValue:dicReaf forKey:keyStr];
	}
	return dicReaf;
}

- (NSArray *) getArrayForKey:(NSDictionary*)dic key:(NSString *)keyStr{
	id dicReaf = [dic objectForKey:keyStr];
	if(dicReaf == nil){
		dicReaf = [NSMutableArray array];
		[dic setValue:dicReaf forKey:keyStr];
	}
	return dicReaf;
}

テーブルの表示で利用。

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	NSLog(@"%d",[[fujidays allKeys] count]);
	NSLog(@"aaa  %@",fujidays);
    return [[fujidays allKeys] count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	cell.textLabel.text = [[fujidays allKeys] objectAtIndex:indexPath.row];
	// Configure the cell.
NSLog(@"bbb  %@",fujidays);
	NSLog(@"bbb  %@",[[fujidays allValues] objectAtIndex:1]);
    return cell;
}

しかし、テーブルが選択された際に動作するメソッドで、
fujidaysのポインタ内がおかしくなっている。。。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
	/*
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
	 [self.navigationController pushViewController:detailViewController animated:YES];
	 [detailViewController release];
	 */
	NSLog(@"push");
	stageViewController *detailViewController = [[stageViewController alloc] initWithNibName:@"stageViewController" bundle:nil];
	NSLog(@"push1");
	detailViewController.dic = fujidays;
	NSLog(@"push2");
	// ...
	// Pass the selected object to the new view controller.
	[self.navigationController pushViewController:detailViewController animated:YES];
	[detailViewController release];
}

なぜ???

NSLog(@"%@",fujidays);

2011-05-18 01:05:39.240 sample08[15216:207] hr.lproj

こんな状態になっている。
ポインタの使い方がおかしいのかな???

2011-05-18 01:07:07.537 sample08[15247:207]   {
    "29\U65e5" =     {
        "green stage" =         (
            css
        );
    };
    "30\U65e5" =     {
        unknown =         (
            "cold play"
        );
    };
    "31\U65e5" =     {
        unknown =         (
            "cold play"
        );
    };
}

途中まではこんな感じ表示できているのに。