0

次の部分を持つアプリケーションがあります。

  • StoreDataController.h
  • StoreDataController.m
  • StoreTableViewController.h
  • StoreTableViewController.m

URL からデータを取得して JSON に変換する StoreDataController のプロパティとメソッドを作成しました。次に、それを配列に格納します。テーブル コントローラにテーブル内の配列を表示させようとしていますが、表示されません。テーブルに配列の内容を表示するにはどうすればよいですか? ここに私が持っているコードがあります:

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
4

1 に答える 1