0

JSON を介してデータを取得する Nsmutable 配列があるとします。このデータは、別の tableviewcontroller を詳細として、別の tableviewcontroller を 3 番目の詳細として持つ tableview controller に表示されます。

プロパティを宣言し、次のように配列を合成しました table1 ビューコントローラー

NSMutableArray *venueData;
NSMutableArray *patientData;

NSMutableArray *moreInfo

2 番目のテーブルは、会場と患者データをドリルダウンします。

テーブル ソースは、次のように json 経由でデータを受け取ります

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request 
                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {


    id results = [JSON valueForKeyPath:@"data"];

    [results enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    [self.venueData addObject:[NSString stringWithFormat:@"%@",[obj valueForKey:@"venueInfo"]]];
    [self.patientData addObject:[NSString stringWithFormat:@"%@",[obj valueForKey:@"patientInfo"]]];
    [self.moreData addObject:[NSString stringWithFormat:@"%@",[obj valueForKey:@"moreInfo"]]];

//additional code etc  
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    //usual code, uiviewcell subclass, dequeueReusableCellWithIdentifier etc

    [[cell venue] setText:[NSString stringWithFormat:@"%@", [venueData objectAtIndex:indexPath.row]]];
    [[cell patient] setText:[NSString stringWithFormat:@"%@", [patientData objectAtIndex:indexPath.row]]];

    return cell;
}

私はセグエを使用しています

if ([segue.identifier isEqualToString:@"ShowDetails"]) 
{
    NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
    SecondViewController *detailViewController = segue.destinationViewController;
    //detailViewController.delegate=self;

    detailViewController.moreInfo=[NSString stringWithFormat:@"%@",[moreData objectAtIndex:selectedRowIndex.row]];
}

私は 3 番目の配列を作成し、それを moreInfo と呼びました。ここには、vevenDescription、venueLocation などの moreInfo を格納しています。

のようにsecondViewController、私の行はその配列の内容によって返されます

最初のテーブルでデータを受信できますが、詳細テーブルにはすべてのインデックスについて同じ情報が表示されます。たとえば、VenuI または Venue2 をクリックすると、会場 1、会場 2、会場 3 などのすべての詳細が表示されます。

最善のアプローチについてアイデアを得ることができますか

4

0 に答える 0