我真的需要更多的幫助!視圖控制器之間傳遞數組?
我想從一個視圖控制器傳遞數組到另一個視圖控制器。我認爲後者是一個'孩子'視圖控制器?
我的代碼如下:
MainViewController.h:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@interface HelloWorldIOS4ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, AVAudioPlayerDelegate> {
NSMutableArray *countProductCode;
UIPopoverController *detailViewPopover;
}
@property (nonatomic, retain) NSMutableArray *countProductCode;
@property (nonatomic, retain) UIPopoverController *detailViewPopover;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
...
@end
MainViewController.m
#import "HelloWorldIOS4ViewController.h"
#import "JSON.h"
#import "PopoverContentViewController.h"
@implementation HelloWorldIOS4ViewController
@synthesize detailViewPopover;
@synthesize countProductCode;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *results = [jsonString JSONValue];
NSLog(@"RETURN: %@", results);
[countProductCode removeAllObjects];
NSArray *products = [results objectForKey:@"items"];
for (NSDictionary *row in products)
{
NSString *code = [row objectForKey:@"ic"];
[countProductCode addObject:code];
}
PopoverContentViewController.countProductCodes = countProductCode;
}
PopoverViewController.h:
@interface PopoverContentViewController : UITableViewController {
NSMutableArray *countProductCodes;
}
@property (nonatomic, retain) NSMutableArray *countProductCodes;
@end
PopoverViewControl ler.m:
#import "PopoverContentViewController.h"
#import "HelloWorldIOS4ViewController.h"
@implementation PopoverContentViewController
@synthesize countProductCodes;
...
我已經削減了很多,但我從的NSLog的周圍點綴的負載知道我取回數據等,但我不能數組countProductCode
傳遞給PopoverViewController's
countProductCodes
陣列。
我不斷收到
「訪問未知 'setCountProductCodes:' 類方法」
錯誤。
這可能真的很愚蠢,我正在做,但它讓我瘋了!
任何人都可以幫忙嗎?
感謝 詹姆斯
這可能是真實的,但並沒有解決父母和孩子視圖控制器之間的強耦合的根本問題。 – GorillaPatch 2010-12-22 11:11:24