0

我有一个分组的 UITableView(2 行,第一行有数据),并试图用来自 Facebook 的数据填充它,但由于某种原因,我遇到了困难。当我尝试使用 NSDictionary 填充它时,它会因“无法识别的选择器”而崩溃,即使(据我所知)我已经正确设置了所有内容。

@property (nonatomic, strong) NSDictionary *album; 
@property (nonatomic, strong) NSArray *fbArray; 
@property (nonatomic, strong) NSArray *album_amount;



-(void)viewDidLoad 
{ 
  [super viewDidLoad]; 
  self.tableView.delegate = self; 
  self.tableview.dataSource = self; 

  [self requestAlbums]; // Here, I request the user's albums from FB
}

- (void)requestAlbums 
{
[FBRequestConnection startWithGraphPath:@"/me/albums/"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
                          TBAppDelegate *delegate = (TBAppDelegate *)[[UIApplication sharedApplication] delegate];

                          managedObjectContext = [delegate managedObjectContext];

                          if(error)
                          {
                              return;
                          }

                          NSArray* collection = (NSArray*)[result data];

                          self.album = [collection objectAtIndex:0];

                          self.album_amount = collection;

    for (int i=0; i  < self.album_amount.count; i++)
    {
        self.album = [self.album_amount objectAtIndex:i];
        self.photoFQL = [NSString stringWithFormat:@"%@/photos", [self.album objectForKey:@"id"]];

        [FBRequestConnection startWithGraphPath:self.photoFQL completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
         {
         }];

        self.fbArray = [self.album objectForKey:@"name"];

                }


                      }];       
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 
NSString *identifier = [NSString stringWithFormat:@"Cell%d", indexPath.row + 1];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];

if (cell.tag == 0)
{        
    NSDictionary *albumDict = [self.fbArray objectAtIndex:indexPath.section]; // Here's where the error is thrown, and I don't know why. I've gone through tutorials, and they either tell me to use indexPath.section or indexPath.row (I have to use indexPath.section as I am using a grouped tableview, right)? 

    NSLog(@"%@", [albumDict objectForKey:@"name"]);

}

if (cell.tag == 1)
{
}

return cell;
}
4

1 回答 1

0

我不确定结果对象是什么,因为它只是一个 ID。

虽然注销。

NSLog (@"result class: %@", NSStringFromClass([result class]));

如果它是字符串或 NSData,则需要 JSON 解析它。如果它是 NSDictionary,则需要使用键访问数据。

于 2013-10-21T00:32:09.387 回答