简体   繁体   中英

Problems linking NSTableView handler class

I have a strange problem in my Cocoa-app. I have a main window with an in it with a controller class ( ). 的主窗口,其中包含一个控制器类( )。 I have made the connections between my NSTableView and the PropValTableHandler, but when the 'numberOfRowsInTableView' method is called it looks like not the 'PropValTableHandler' initialized in 'AddDelegate' is used, since the 'propMan' field is not initialized (it is like the normal init is used, so it has to be another instance of this class). Am I doing something wrong? I have another NSTableView handler in another window, that works, but it does not have a custom init method.

Source codes:

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize propValTableController = _propValTableController;

-(id) init
{
    self = [super init];

    if (self)
    {
        _propMan = [[OCPropertyManager alloc]initWithPath:"./data/"];
        _propValTableController = [[PropValTableHandler alloc] 
                                   [initWithPropManager:_propMan];
    }

    return self;
}

@interface PropValTableHandler : NSObject <NSTableViewDataSource>

@property IBOutlet NSTableView * constants;
@property OCPropertyManager    * propMan;

-(id) initWithPropManager:(OCPropertyManager*)pm;

-(NSInteger) numberOfRowsInTableView:(NSTableView *)tableView;

@end


#import "PropValTableHandler.h"

@implementation PropValTableHandler


-(id) initWithPropManager:(OCPropertyManager*)pm
{
    self = [super self];
    if (self)
    {
        self.propMan = pm;
    }

    return self;
}

/*********** TABLEVIEW DATASOURCE ******************/
-(NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
    NSInteger count = [_propMan.consts count];
    return count;
}
/**************************************************/

@end

I have solved the problem by adding a

@property IBOutlet AppDelegate *parent;

for the PropValTableHandler class and making the connections. This way I can use:

parent.propMan

where ever I need it without passing a reference to it in the init method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM