-1
NSMutableArray
다른 클래스에서 액세스하려고하는데 다음 코드를 사용할 때 코드를 호출 할 때 값이 없습니다.다른 클래스의 NSMutableArray에 액세스
TableViewController.h
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *imageURLs;
@end
TableViewController.m
#import "TableViewController.h"
#import "ImageCell.h"
#import "ParseJSON.h"
#import "AsyncImageView.h"
@implementation TableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ParseJSON *json = [[ParseJSON alloc] init];
[json Parse];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ImageCell *cell = [[ImageCell alloc] init];
cell.firstImage.imageURL = self.imageURLs[0];
cell.secondImage.image = self.imageURLs[1];
cell.thirdImage.image = self.imageURLs[2];
return cell;
}
@end
ParseJSON.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "TableViewController.h"
@interface ParseJSON : NSObject
- (void)Parse;
@end
ParseJSON.m
#import "ParseJSON.h"
@implementation ParseJSON
- (void)Parse
{
NSData *imageData = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:@"http://www.delta.rhystowey.com/json/main.json"]];
NSError *error;
NSDictionary *imageDictionary = [NSJSONSerialization
JSONObjectWithData:imageData
options:kNilOptions
error:&error];
NSMutableArray *URLs = [NSMutableArray array];
if(error)
{
NSLog(@"%@", [error localizedDescription]);
}
else {
NSArray *images = imageDictionary[@"Images"];
for (NSDictionary *image in images)
{
[URLs addObject:image[@"url"]];
}
}
TableViewController *tvc = [[TableViewController alloc] init];
tvc.imageURLs = URLs;
}
@end
귀하의 질문에 정확히 무엇입니까
viewDidLoad
에서 다음? '? '로 끝나는 질문에 유의하십시오. – Popeye
완전히 새로운'tvc' 객체를 만든 것 같습니다. 그것은 당신이 생각하는 것이 아닙니다. 포인터인지 확인하십시오. 포인터가 다르다는 것을 알 수 있어야합니다. – Larme