我无法理解如何使用所有日期填充表格。仅返回9-1-2012而非2012年8月31日。我尝试过一些事情,例如在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;
这是一张照片
答案 0 :(得分:3)
我认为你很接近,因为你的数组具有所有值,而不是同时。尝试移动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];
}