需要真正的帮助!!!
我正在尝试使用第二类中第一类创建的数据。我一直在搜索Youtube和StackOverflow超过1周。每当我认为我很接近时,就会有一些我无法理解的缺失。我的最新尝试来自2011年发布的这个网站(在课程之间传递数据objective-c),当应用程序编译时,我看不到第二类中的数据。
更具体。我正在使用2个类,因为数据是在用户选择的组(第1类)中收集的,并将在屏幕上显示在第2类的表中。来自源的6个NSMutable Arrays传递给第2类中的6个不同。我将继续尝试解决,但我可以使用帮助。
以下是我在2011年文章中设计的内容:
第一类.h代码(部分):
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import "ReportsOutput.h"
//@class AppDelegate;
@class ReportsOutput;
@interface ReportsClass : NSWindowController<NSApplicationDelegate,NSMenuDelegate,NSWindowDelegate>{
ReportsOutput *ro;
//Shared Data arrays
NSMutableArray *tblYrScott;
NSMutableArray *tblYrExt;
NSMutableArray *tblYrYear;
NSMutableArray *tblYrType;
NSMutableArray *tblYrPrice;
NSMutableArray *tblYrDescription;
...... added code
@property(nonatomic,retain)NSMutableArray *tblYrScott;
@property(nonatomic,retain)NSMutableArray *tblYrExt;
@property(nonatomic,retain)NSMutableArray *tblYrType;
@property(nonatomic,retain)NSMutableArray *tblYrYear;
@property(nonatomic,retain)NSMutableArray *tblYrPrice;
@property(nonatomic,retain)NSMutableArray *tblYrDescription;
第一类.m代码:
- (IBAction)btnShowDataOutput:(id)sender {
//pass data from Reports Class to Report Output Class
ReportsOutput *objReportsOutput = [[ReportsOutput alloc]init];
[objReportsOutput.tblScott setArray: tblYrScott];
[objReportsOutput.tblExt setArray:tblYrDescription];
[objReportsOutput.tblYear setArray:tblYrYear];
[objReportsOutput.tblType setArray:tblYrType];
[objReportsOutput.tblDescription setArray:tblYrDescription];
// open Reports Output Window
if (ro == nil){
ro = [[ReportsOutput alloc] initWithWindowNibName:@"ReportsOutput"];
}
[ro showWindow:nil];
}
第二课.h代码:
#import <Cocoa/Cocoa.h>
#import "ReportsClass.h"
@interface ReportsOutput : NSWindowController{
//shared data arrays
NSMutableArray *tblScott;
NSMutableArray *tblExt;
NSMutableArray *tblYear;
NSMutableArray *tblType;
NSMutableArray *tblPrice;
NSMutableArray *tblDescription;
}
@property(nonatomic,strong) NSMutableArray *tblScott;
@property(nonatomic,strong) NSMutableArray *tblExt;
@property(nonatomic,strong) NSMutableArray *tblYear;
@property(nonatomic,strong) NSMutableArray *tblType;
@property(nonatomic,strong) NSMutableArray *tblPrice;
@property(nonatomic,strong) NSMutableArray *tblDescription;
@end
第二课.m代码:
#import "ReportsOutput.h"
//#import "ReportsClass.h"
@interface ReportsOutput ()
@end
@implementation ReportsOutput
@synthesize tblScott;
@synthesize tblExt;
@synthesize tblType;
@synthesize tblPrice;
@synthesize tblYear;
@synthesize tblDescription;
- (void)windowDidLoad {
[super windowDidLoad];
}
-(void)awakeFromNib{
[self dataCheck];
}
-(void)dataCheck{
int a;
for (a=0; a<[self.tblScott count]; a++){
NSLog(@"@i,%d :%@: %@: %@: %@: %@: %@",a,[tblScott objectAtIndex:a],[tblExt objectAtIndex:a],[tblYear objectAtIndex:a],[tblType objectAtIndex:a],[tblPrice objectAtIndex:a],[tblDescription objectAtIndex:a]);
}
}
答案 0 :(得分:3)
在btnShowDataOutput中,您创建objReportsOutput,但该方法在方法结束后立即消失。您不需要创建objReportsOutput。而是直接在ReportsOutput窗口控制器上设置属性:
if (ro == nil){
ro = [[ReportsOutput alloc] initWithWindowNibName:@"ReportsOutput"];
}
ro.tblScott = self.tblYrScott
ro.tblExt = self.tblYrExt
ro.tblYear = self.tblYrYear
ro.tblType = self.tblYrType
ro.tblDescription = self.tblYrDescription
[ro showWindow:nil];