0

テーブルにすべての日付を入力する方法を理解するのに問題があります。2012年8月31日ではなく、2012年9月1日のみを返します。numberofrowssectionで日数やスロットを使用するなど、いくつか試してみました。.countと関係があると思いますが、どこにあるのかわかりません。しかし、私はまだそれを理解していません。それはまだ9/1辞書を投稿しているだけです。tableviewcellにすべての辞書を表示するにはどうすればよいですか。わかりやすく、画像を添付してください。私のコード:

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];

    NSDictionary* myslots =[json objectForKey:@"slots"];
    NSLog(@"allslots: %@", myslots);

    for (NSString *slotKey in myslots.allKeys) {
    NSDictionary *slot = [myslots valueForKey:slotKey];
       UPDATED:
        self.timesArray = [[NSMutableOrderedSet alloc] init];
    for (NSDictionary *myDays in slot){

        if ([[myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]])

           [self.timesArray addObject:[myDays objectForKey:@"begin"]];
         //NSLog(@"This is the times count: %@", timesArray.count);
    }

       NSLog(@"These are the times avail: %@", self.timesArray);          

    [self.tableView reloadData];
    }
}

これは次のようになります。

2012-08-31 16:34:57.074 GBSB[780:15b03] These are the times avail: {(
    "2012-08-31 09:00:00 America/Los_Angeles",
    "2012-08-31 13:00:00 America/Los_Angeles",
    "2012-08-31 14:00:00 America/Los_Angeles",
    "2012-08-31 15:00:00 America/Los_Angeles",
    "2012-08-31 16:00:00 America/Los_Angeles"
)}
2012-08-31 16:34:57.074 GBSB[780:15b03] These are the times avail: {(
    "2012-09-01 09:00:00 America/Los_Angeles",
    "2012-09-01 10:00:00 America/Los_Angeles",
    "2012-09-01 11:00:00 America/Los_Angeles",
    "2012-09-01 12:00:00 America/Los_Angeles",
    "2012-09-01 13:00:00 America/Los_Angeles",
    "2012-09-01 14:00:00 America/Los_Angeles",
    "2012-09-01 15:00:00 America/Los_Angeles",
    "2012-09-01 16:00:00 America/Los_Angeles"
)}

これが私が.hで試したことです

@property (nonatomic, retain) NSMutableOrderedSet *timesArray;

.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.timesArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    //cell.textLabel.text = timesArray;
    cell.textLabel.text = [self.timesArray objectAtIndex:indexPath.row];
    return cell;

これが写真です 辞書を1つだけ表示する

4

1 に答える 1

3

配列にはすべての値が含まれているので、同時にではないので、あなたは近くにいると思います。self.timesArray = [[NSMutableOrderedSetalloc]init];を移動してみてください。forループの前にアップして、一度だけ初期化されるようにします。また、最後のNSLogとtableViewreloadDataを次のように下に移動します。

    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];

    NSDictionary* myslots =[json objectForKey:@"slots"];
    self.timesArray = [[NSMutableOrderedSet alloc] init];
    NSLog(@"allslots: %@", myslots);

    for (NSString *slotKey in myslots.allKeys) {
        NSDictionary *slot = [myslots valueForKey:slotKey];
       UPDATED:
        for (NSDictionary *myDays in slot){

            if ([[myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]])

               [self.timesArray addObject:[myDays objectForKey:@"begin"]];
            //NSLog(@"This is the times count: %@", timesArray.count);
        }

    }
    NSLog(@"These are the times avail: %@", self.timesArray);
    [self.tableView reloadData];
}
于 2012-09-02T00:40:38.800 に答える