好吧,我认为我在这里遇到的问题很冗长,难以理解。我会简化我的问题:
nextPage
的方法,它告诉int变量inPageNumber
,将一个变量添加到自身并调用另一个 InController 名为updateTable
的方法。updateTable
清除其当前数据的表格 inTable ,并使用与其inPageNumber
检索到的页码相关的数据填充该表。NSBox
内。NSBox
子类化为名为 CustomViewPagination 的类,以满足这些打印要求,覆盖其分页方法。基本上,当需要新的打印页面时,它会尝试再次打印相同的区域,但是调用nextPage
以使用顺序页面的数据填充表格。到目前为止我?
默认情况下,我在 CustomViewPagination ,beginPageInRect
中覆盖的一种分页方法会自动为每个打印页面调用。因此,我调用nextPage
的 InController 方法,更改当前打印页面的 inTable 数据。
我的问题是当我从 CustomViewPagination 类调用nextPage
( InController 中的方法)时。它没有做任何事情,当我调试它时,我发现方法中所需的所有变量都是零。但是,当我从 InController 中调用nextPage
时,它们是正确的值。
InController.h:
#import <Cocoa/Cocoa.h>
#import "CustomViewPagination.h"
@interface InController : NSObject {
IBOutlet NSWindow *inPreview;
IBOutlet CustomViewPagination *inSheet;
NSArray *iSelectedIn;
NSMutableArray *records;
int inPageNumber;
}
@property (nonatomic, retain) NSArray *iSelectedIn;
@property (nonatomic, retain) NSMutableArray *records;
InController.m:
#import "InController.h"
@implementation InController
@synthesize iSelectedIn, records;
- (IBAction) inNextPage:(id)sender {
inPageNumber = inPageNumber + 1;
NSLog(@"inPageNumber called ok");
[self updateIn];
}
- (IBAction)updateInvoice:(id)sender {
//wipe all current records and refresh empty table
[records removeAllObjects];
[inPreviewTable reloadData];
for (NSArray *s in [[iSelectedIn valueForKey:@"inJobList"] lastObject]) {
NSString *jLT = [s valueForKey:@"inJT"];
NSString *jLH = [s valueForKey:@"inJHo"];
NSString *jLC = [s valueForKey:@"inJC"];
// etc.
// if CustomViewPagination called this, records is nil, so nothing
// is cleared, and there's no *s for iSelectedIn as iSelectedIn
// is found to be nil. If InController called this, it works fine.
CustomViewPagination.h:
#import <Cocoa/Cocoa.h>
@class InController;
@interface CustomViewPagination : NSBox {
InController *inControllerInstance;
}
@end
CustomViewPagination.m:
#import "CustomViewPagination.h"
#import "InController.h"
@implementation CustomViewPagination
- (void) awakeFromNib {
inControllerInstance = [[InController alloc] init];
}
- (void)beginPageInRect:(NSRect)aRect atPlacement:(NSPoint)location {
int pageCounter = [[NSPrintOperation currentOperation] currentPage];
if (pageCounter == 1) {
// Don't respond to 1st page, do nothing.
} else {
[inControllerInstance inNextPage:self];
}
[super beginPageInRect:aRect atPlacement:location];
}
@end
答案 0 :(得分:0)
您在InController
(inPreview
&amp; inSheet
)中使用了2个IBOutlet,但在InController
CustomViewPagination's
中以编程方式创建了awakeFromNib
。
奥特莱斯是如何连接的? (不能来自IB内部,因为您以编程方式创建InController
实例)。这将解释为什么两者都是nil
。