我有一个包含以下部分的应用程序:
- StoreDataController.h
- StoreDataController.m
- StoreTableViewController.h
- StoreTableViewController.m
我在 StoreDataController 中创建了一个属性和方法,用于从 URL 检索数据并将其转换为 JSON。然后我将它存储在一个数组中。我试图让表控制器在表中显示数组,但它没有显示。我需要做什么才能让表格显示数组的内容?这是我的代码:
StoreDataController.h
@interface StoreDataController : NSObject
@property (nonatomic, retain) NSArray *storeNames;
-(void)addStoreNamesObject:(NSArray *)storeNames;
@end
StoreDataController.m
#import "StoreDataController.h"
#import "SBJson.h"
@implementation StoreDataController
-(void)addStoreNamesObject:(NSArray *)storeNames
{
NSString *strURL = [NSString stringWithFormat:@"http://10.247.245.87/stores/dodge.php"];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
storeNames = [strResult JSONValue];
}
@end
StoreTableViewController.h
#import <UIKit/UIKit.h>
@class StoreDataController;
@interface StoreTableViewController : UITableViewController
@property (nonatomic, retain) StoreDataController *storeNameController;
@end
StoreTableViewController.m
#import "StoreTableViewController.h"
#import "StoreDataController.h"
@interface StoreTableViewController ()
@end
@implementation StoreTableViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _storeNameController.storeNames.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [_storeNameController.storeNames objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end