TableViewCells和字典数组

我无法理解如何用所有的date填充我的表。 只返回2012年9月1日至2012年8月31日。 我已经尝试了一些东西,如使用我的天和插槽numberofrowsctions。 我认为这与.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; 

这是一张照片 只显示一个字典

我认为你很接近,因为你的数组有所有的价值,而不是在同一时间。 尝试移动self.timesArray = [[NSMutableOrderedSet alloc] init]; 在for循环之前,以便它只被初始化一次。 另外,像这样移动最后的NSLog和tableView reloadData:

  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]; }