gpt4 book ai didi

ios - 无法保存 JSON 数据以供多个 UIView 使用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:04 27 4
gpt4 key购买 nike

<分区>

我在访问我提取的 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 后,我从 RightViewController 中的 NSLog(@"%@", notification.userinfo); 得到以下输出:

    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";
}
);
}

请不要介意名字。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com