我得到这个 JSON:
{
"timestamp": "2013-05-03T22:03:45Z",
"resultsOffset": 0,
"status": "success",
"resultsLimit": 10,
"breakingNews": [],
"resultsCount": 341,
"feed": [{
"headline": "This is the first headline",
"lastModified": "2013-05-03T21:33:32Z",
"premium": false,
"links": {
"api": {
并使用它在 UITableView 中加载它:
@property (strong, nonatomic) NSArray *headlinesArray;
- (void)viewDidLoad
{
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[NSString stringWithFormat:@"/now/?leafs=%@&teas=%@&apikey=xxxxx", leafAbbreviation, teaID] usingBlock:^(RKObjectLoader *loader) {
loader.onDidLoadObjects = ^(NSArray *objects){
premiumArray = objects;
[_tableView reloadData];
};
[loader.mappingProvider setMapping:[Feed mapping] forKeyPath:@"feed"];
loader.onDidLoadResponse = ^(RKResponse *response){
//NSLog(@"BodyAsString: %@", [response bodyAsString]);
};
}];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"standardCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
NSString *headlineText = [NSString stringWithFormat:@"%@", feedLocal.headline];
cell.textLabel.text = headlineText;
return cell;
}
标题类模型:
@property (strong, nonatomic) NSString *headline;
@property (strong, nonatomic) Links *linksHeadline;
有什么方法可以检查是否premium
在true
JSON 中,而不是在 ? 中显示标题UITableView
?
编辑 1
我添加@property (strong, nonatomic) NSArray *premiumArray;
了与 相关的正确数据premium
,所以现在我只需要帮助查看该数组中的链接,TRUE
这样我UITableView
就不会显示任何溢价 = TRUE 的标题。
编辑 2
我发布了viewDidLoad
上面的代码。
编辑 3
饲料.h
@property (nonatomic, strong) NSString *headline;
@property (nonatomic, strong) NSString *premium;
饲料.m
+ (RKObjectMapping *)mapping {
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[self class] usingBlock:^(RKObjectMapping *mapping) {
[mapping mapKeyPathsToAttributes:
@"headline", @"headline",
@"premium", @"premium",
nil];
}];
return objectMapping;
}
编辑
I added this per some answers, but still couldn't get it working, any thoughts?
@property (strong, nonatomic) NSArray *premiumArray;
@property (strong, nonatomic) NSMutableArray *myMutable;
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[NSString stringWithFormat:@"/now/?leagues=%@&teams=%@&apikey=5qqpgrsnfy65vjzswgjfkgwy", leagueAbbreviation, teamID] usingBlock:^(RKObjectLoader *loader) {
loader.onDidLoadObjects = ^(NSArray *objects){
//sports = objects;
premiumArray = objects;
[_tableView reloadData];
};
[loader.mappingProvider setMapping:[Feed mapping] forKeyPath:@"feed"];
loader.onDidLoadResponse = ^(RKResponse *response){
//NSLog(@"BodyAsString: %@", [response bodyAsString]);
};
}];
self.myMutable = [[premiumArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"premium = YES"]] mutableCopy];