【发布时间】:2013-03-23 12:52:16
【问题描述】:
其实我是iOS编程新手,我正在努力自学。
我有一个带有标题部分的分段表视图,但我希望该视图能够在点击此部分时折叠展开部分中的行。
我用这个教程:http://blog.paxcel.net/blog/expandablecollapsible-table-for-ios/
但在我的应用程序中,我有一个 Json 文件而不是 Plist 文件。
所以我在 setCategoryArray() 函数中使用:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: @"http://......./catjsonf.php"]];
NSError* error;
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
jsonResults = [json objectForKey:@"nodes"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
而不是:
NSURL *url = [[NSBundle mainBundle] URLForResource:@”CategoryList” withExtension:@”plist”];
NSArray *mainArray = [[NSArray alloc] initWithContentsOfURL:url];
但它不起作用 - 我应该做点别的吗?
【问题讨论】:
-
您正在从 web 服务获取数组。需要花时间。使用异步方法并在
connectionDidFinishLoading中重新加载您的表。
标签: iphone ios json uitableview