我尝试进行 Facebook Graph 调用并将一些项目添加到数组中。这些项目被添加到一个 for 循环中,并且数组看起来很好。但是在 for 循环之后,这些项目就消失了。
我将 xcode 4.5 与 Facebook SDK 3.1 一起使用。
我错过了什么?
表视图控制器.m
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController {
NSMutableArray *recipes;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
recipes = [NSMutableArray arrayWithObjects:@"Egg Benedict", nil];
[recipes addObject:@"foobar"];
NSLog(@"recipes before FBRquestConnection: %@", recipes);
[FBRequestConnection
startWithGraphPath:@"search?type=place¢er=37.785834,-122.406417"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
for (id item in [result objectForKey:@"data"]) {
[recipes addObject:[item objectForKey:@"name"]];
}
NSLog(@"recipes after for-loop: %@", recipes);
NSLog(@"amount of recipes after for-loop: %u", [recipes count]);
}
}];
NSLog(@"amount of recipes after FBRequestConnection: %u", [recipes count]);
}
调试控制台输出
2012-12-27 23:09:44.056 barbar[3481:19a03] recipes before FBRquestConnection: (
"Egg Benedict",
foobar
)
2012-12-27 23:09:44.056 barbar[3481:19a03] amount of recipes after FBRequestConnection: 2
2012-12-27 23:09:44.516 barbar[3481:19a03] recipes after for-loop: (
"Egg Benedict",
foobar,
"Union Square, San Francisco",
"Benefit Cosmetics",
"San Francisco | The Official Guide",
"BareMinerals by Bare Escentuals",
"Viator.com",
"Bleacher Report",
"Downtown San Francisco",
"AMC Metreon 16",
"Cheesecake Factory",
SquareTrade,
"Westfield San Francisco Centre",
"Bloomingdale's San Francisco",
"Macy's San Francisco Union Square",
Xoom,
"Parc 55 Hotel",
"Pottery Barn",
"AT&T Park",
Bebo,
Snapfish,
"Hilton San Francisco Union Square",
uTorrent,
"The Westin St. Francis",
TRUSTe,
"Apple Retail Store - San Francisco"
)
2012-12-27 23:09:44.516 barbar[3481:19a03] amount of recipes after for-loop: 26
干杯——杰里克