Ios 无法使用JSON数据设置UITableView节标题
我的解析云代码正在将JSON数据返回到我的iOS应用程序,我想将我的Ios 无法使用JSON数据设置UITableView节标题,ios,objective-c,json,uitableview,Ios,Objective C,Json,Uitableview,我的解析云代码正在将JSON数据返回到我的iOS应用程序,我想将我的UITableView的节标题设置为它返回的搜索词属性。我试图引用matchCenterDictionary,以便专门选择该键,但它只是将(null)显示为部分标题 在设置单元格的文本标签时,以这种方式引用字典的效果非常好,所以我不确定为什么它不起作用 MatchCenterViewController.h: #import <UIKit/UIKit.h> #import <Parse/Parse.h>
UITableView
的节标题设置为它返回的搜索词
属性。我试图引用matchCenterDictionary
,以便专门选择该键,但它只是将(null)
显示为部分标题
在设置单元格的文本标签时,以这种方式引用字典的效果非常好,所以我不确定为什么它不起作用
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
@interface MatchCenterViewController : UIViewController <UITableViewDataSource>
@property (nonatomic) IBOutlet NSString *itemSearch;
@property (nonatomic, strong) NSArray *imageURLs;
@property (strong, nonatomic) NSString *matchingCategoryCondition;
@property (strong, nonatomic) NSString *matchingCategoryLocation;
@property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
@property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;
@property (strong, nonatomic) NSArray *matchCenterArray;
@property (strong, nonatomic) NSDictionary *matchCenterDictionary;
@end
您应该使用self.matchCenterArray而不是\u matchCenterDictionary 您必须通过解析数据来完成此操作
NSString *searchTerm = [[self.matchCenterArray objectAtIndex:section] objectForKey:@"Search Term"];
遵循Adrian的说明(使用self.matchCenterArray) 然后更改此选项:
NSString *searchTerm = [self.matchCenterArray objectForKey:@"Search Term"];
为此,例如:
NSString *searchTerm = [[self.matchCenterArray firstObject] objectForKey:@"Search Term"];
搜索词位于数组中的每个NSDictionary中。。例如,您需要首先检索firstObject。什么是
\u matchCenterDictionary
?没有用于此的ivar或属性。它是如何设置的?@rmaddy,那是我试图将其设置为公共属性的,我一定是在发布之前意外地从头文件中删除了它,我已经编辑了我的帖子。好的,但它设置在哪里?设置好了吗?现在我再看一遍,我意识到我还没有设置好。正确的方法是什么?这取决于你。这是您的数据。这会导致应用程序崩溃,说明由于未捕获的异常“NSRangeException”而终止应用程序,原因:“***-[\uu NSArrayI objectAtIndex:]:索引0超出空数组的界限”,这很奇怪,因为当我在CellForRowatingIndexPath
中引用数组时,它不会给我那个错误。这意味着self.matchCenterArray中没有数据。我将从ViewDidDisplay中删除self.matchCenterArray=新数组。此外,您不必在块中执行dispatch_async(dispatch_get_main_queue())来重新加载表中的数据。您可以直接调用reloadData函数。实际上,他需要使用主队列,因为块在后台运行,UI在主线程上运行。。
NSString *searchTerm = [self.matchCenterArray objectForKey:@"Search Term"];
NSString *searchTerm = [[self.matchCenterArray firstObject] objectForKey:@"Search Term"];