0

私は辞書と辞書ごとの文字列の数を含むplistを持っています。以下のURLに表示してください。このアイテムのリストはplistに数千あります。

これらのplistデータをUItableviewに表示する必要があります

eneter画像

これを行う方法?

私のコード:

- (void)viewWillAppear:(BOOL)animated
{
    // get paths from root direcory
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                                 NSUserDomainMask, YES);
    NSString *documentsDirectory = [documentPaths objectAtIndex:0];
    NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"p.plist"];

    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath];

    valueArray = [dict objectForKey:@"title"];

    self.mySections=[valueArray copy];
    NSLog(@"value array %@",self.mySections);

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.mySections count];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    NSString *key = [[self.mySections objectAtIndex:section]objectForKey:@"pass"];
    return [NSString stringWithFormat:@"%@", key];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.mySections count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];

    cell.textLabel.text = [[self.mySections objectAtIndex:row] objectForKey:@"title"];
    cell.detailTextLabel.text=[[self.mySections objectAtIndex:section] objectForKey:[allKeys objectAtIndex:1]];

    return cell;
}
4

1 に答える 1

1

配列の最後を使い果たしました。

これはおそらく、各セクションの行数を 5 にハードコーディングしたためです。各セクションに実際に 5 行がない限り、ここで動的な値を返す必要があります。

于 2012-12-17T10:58:24.013 に答える