0

ループ内にこのようなデータ構造があります。生成された配列のコンテンツであるself.practiceは、tableviewControllerの動的テーブルビューに入力する必要があります。

    // new NSDictionary
    NSDictionary *highway = [[NSDictionary alloc] initWithObjectsAndKeys:@"Highway", @"description",
                              @"H", @"namekey",
                              [NSString stringWithFormat:@"%i", aHours], @"hours",
                              aHoursDefault.stringValue, @"hoursdefault",
                              [self.classlist objectAtIndex:i], @"driverclass",
                              nil];
    NSDictionary *freeway = [[NSDictionary alloc] initWithObjectsAndKeys:@"Freeway", @"description",
                              @"F", @"namekey",
                              [NSString stringWithFormat:@"%i", fHours], @"hours",
                              fHoursDefault.stringValue, @"hoursdefault",
                              [self.classlist objectAtIndex:i], @"driverclass",
                              nil];

    NSDictionary *stateHigway = [[NSDictionary alloc] initWithObjectsAndKeys:@"stateHighway", @"description",
                              @"S", @"namekey",
                              [NSString stringWithFormat:@"%i", sHours], @"hours",
                              sHoursDefault.stringValue, @"hoursdefault",
                              [self.classlist objectAtIndex:i], @"driverclass",
                              nil];



    // Values of Dictionary assign to array

    [self.practiceOverviewData addObject:highway];
    [self.practiceOverviewData addObject:freeway];
    [self.practiceOverviewData addObject:stateHighway];



    // put those arrays in the "Big Array" for my tableview
    [self.practice addObject:self.practiceOverviewData];

現在、cellForRowAtIndexPathにあります。内部配列からキー値にアクセスできません。

    cell.textLabel.text = [[self.practice objectAtIndex:indexPath.row] objectForKey:@"description"];
4

1 に答える 1

0

あなたのself.practicecontains配列、これはpracticeOverviewDataあなたのpracticeOverviewDatacontainsディクショナリです:

[self.practice objectAtIndex:n] = PracticeOverviewData

[[self.practice objectAtIndex:n] objectAtIndex:n]=高速道路/高速道路/州道

次のようにデータにアクセスします。

[[[self.practice objectAtIndex: n] objectAtIndex:indexPath.row] objectForKey:@"description"];

編集:

[self.practiceOverviewData addObject:highway];
[self.practiceOverviewData addObject:freeway];
[self.practiceOverviewData addObject:stateHighway];

NSDictionary *newDictionary = [NSDictionary dictionaryWithObjectAndKey:
                               self.practiceOverviewData,@"roads_data",nil];

[self.practice addObject:newDictionary];

NSArray *data = [NSArray array];
for (int i = 0; i < [practice count]; i++) {
    if ([[self.practice objectAtIndex:i] isKindOfClass:[NSDictionary class]]) {
        data = [(NSDictionary*)[self.practice objectAtIndex:i]objectForKey:@"road_data"];
    }
}

cellForRowAtIndexPath:.。

 //of course you want to declare data in your header file to access it in your cellForRow..
cell.textLabel.text = [(NSDictionary*)[data objectAtIndex:indexPath.row] objectForKey:@"description"];

編集:このコードは、self.practice異なる種類のデータが含まれている可能性があることを前提としています。

于 2012-09-18T05:42:54.410 に答える