【发布时间】:2013-01-17 12:35:39
【问题描述】:
我能够解析 JSON 并将其存储在我的 FirstViewController 中名为 json 的 NSMutableArray 中。问题是,我不知道如何从我的视图控制器访问我的FirstViewController 中的数组。
编辑!!!
我将代码从 AppDelegate 移到了我的 FirstViewController,因为这不是一个好习惯。
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
{
NSMutableArray *jsonData;
}
@property (nonatomic, strong) NSMutableArray *jsonData;
@end
FirstViewController.m
@synthesize jsonData;
NSURL *url = [NSURL URLWithString:@"http://search.twitter.com/search.json?q=coredata"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
self.json = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.secondJSON = [self jsonData];
[[self navigationController] pushViewController:secondViewController animated:YES];
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
NSMutableArray *secondJSON;
}
@property (nonatomic, strong) NSMutableArray *secondJSON;
@end
SecondViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", [self secondJSON]);
}
输出
2013-02-03 00:16:17.749 Subscription[24669:c07] (null)
我错过了什么吗?
【问题讨论】:
-
你想将数组从一个viewccontroller传递到另一个??
-
是的,但它不起作用。
标签: iphone ios objective-c ipad uiviewcontroller