我在访问我提取的 JSON 数据时遇到了一些问题。我正在使用 JSONModel 来获取我的 JSON 数据,如下所示:
在我的 LeftViewController.m 的顶部
@interface LeftViewController ()
{
PostgresFeed* _feed;
}
然后在下面:
-(void)viewDidAppear:(BOOL)animated
{
JSONHTTPClient getJSONFromURLWithString:@"myurl" completion:^(NSDictionary *json, JSONModelError *err) {
NSError *error = nil;
_feed = [[PostgresFeed alloc] initWithDictionary:json error:&error];
NSLog(@"Players: %@", feed.player);
[self.tableView reloadData];
}];
}
-(void)fetchedData:(NSData *)responseData
{
NSError* error;
NSDictionary* playerData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSMutableDictionary* player = [playerData objectForKey:@"player"];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
_feed.player = [NSMutableArray array];
}
return self;
}
在我的 PostgresFeed.h
@property (nonatomic, strong) NSString *playerName;
@property (nonatomic, strong) NSString *currentScore;
@property (nonatomic, strong) NSArray *totalPenalties;
@property (nonatomic, strong) NSString *timePlayed;
我的 PostgresFeed.m 中没有任何内容
我知道当我这样做时,我会将所有我想要的数据放入我的 LeftViewController,它是 MasterDetail 的 tableView。当我查看时,NSLog(@"Players: %@", feed.player);
我可以说我正在从数据库中获取我想要的所有数据。
如何访问我知道必须填充 DetailViewController 的这些数据?我应该使用 NSUserDefaults 吗?我应该创建一个新类来获取、解析和保存这些数据吗?
我对这一切都很陌生,因此非常感谢指向教程或教程之类的说明。如果需要更多代码或详细信息,请告诉我。
****编辑****
按照@soryngod 的建议应用 NSNotificationCenter 后,我NSLog(@"%@", notification.userinfo);
在 RightViewController 中得到以下输出:
2013-07-04 12:20:26.208 PlayerTracking[25777:11303] {
player = (
{
currentScore = "4";
totalPenalties = (
);
id = 9;
name = "Jakob Melon";
timeStarted = "2013-06-05 19:56:10";
},
{
currentScore = 16;
totalPenalties = (
);
id = 10;
name = "John China";
timeStarted = "2013-06-06 17:21:300";
},
{
currentScore = 178;
totalPenalties = (
);
id = 11;
name = "Jason Dog";
timeStarted = "2013-06-07 19:26:10";
},
{
currentScore = 1233;
totalPenalties = (
);
id = 12;
name = "Fox Wolfe";
timeStarted = "2013-06-05 19:56:10";
},
{
currentScore = 234;
totalPenalties = (
);
id = 13;
name = "Dakota Cool";
timeStarted = "2013-06-05 19:56:10";
},
{
currentScore = "34234";
totalPenalties = (
);
id = 14;
name = "Max Face";
timeStarted = "2013-06-05 19:00:30";
},
{
currentScore = "2342";
totalPenalties = (
);
id = 15;
name = "Jonatan Blah";
timeStarted = "2013-06-05 18:00:30";
},
{
currentScore = "234234";
totalPenalties = (
);
id = 16;
name = "Thomas Bus";
timeStarted = "2013-06-05 19:56:10";
},
{
currentScore = 34566;
totalPenalties = (
);
id = 17;
name = "Super Cake";
timeStarted = "2013-06-05 17:51:30";
},
{
currentScore = "23463";
totalPenalties = (
);
id = 18;
name = "Duke Nukem";
timeStarted = "2013-06-07 19:26:10";
},
{
currentScore = "12362";
totalPenalties = (
);
id = 19;
name = "Gordon Freeman";
timeStarted = "2013-06-05 19:56:10";
}
);
}
请不要介意名字。