开发者

Preference Pane & NSTableView bindings

I am trying to create a preference pane which will reside within system preferences. All the bindings are done as usual (for a normal windowed application), but when the setter for the binding property is called (data is updated), the table data does not reset. Are preference panes capable of updating table data via bindings? I have also tried to use a table data source unsuccessfully.

To clarify, I have an NSMutableArray property in my prefPane's main class, an object representing the prefPane's main class, and an arrayController in IB which is bound to the table column. in the init method of the prefPane's main class, I set the value of the NSMutableArray, which is properly reflected in the pref pane, however, (just to test if bindings work), i have an NSTimer which resets the value of my NSMutable array when it finishes. A console message tells me that the value is properly reset, however, the changes are not reflected in the pref pane.

So in my current version i use the following code to set the properties to arbitrary values (simplified to try to get bindings to work at开发者_如何学编程 all). The property value is then reset by a timer 10 seconds later. Although the property is correctly updated (verified by console log), the pref pane does not reflect the changes in the tableview. Unfortunately, I cannot post screenshots of the bindings. I have an object in IB for the syncFrontEndPref class. I then have an arraycontroller bound to this object w/ a model key path of listArray. Then my table column is bound to the arraycontroller arranged objects. This loads properly with "test", "test1", "test2" in the pref pane (as populated from the init method). However, when repopulated from the timer, the changes are not reflected in the pref pane (although console log confirms listArray has indeed changed.

Here is the code:

@interface syncFrontEndPref : NSPreferencePane 
{

    NSMutableArray *listArray;
    NSNumber *syncInt;
    AuthenticateUser *newUser;
    NSMutableArray *syncIntervalList;
    IBOutlet NSTableView *theTableView;

}

@property (retain) NSMutableArray *listArray;
@property (retain) NSMutableArray *syncIntervalList;

- (void) mainViewDidLoad;
-(IBAction)syncIntervalValueChanged:(id)sender;
-(IBAction)tableViewSelected:(id)sender;



@implementation syncFrontEndPref

@synthesize listArray, syncIntervalList;

-(id) init{

    //populate nsarray w/ list data to display
    //[self setListArray: [NSMutableArray arrayWithArray:[[[NSDictionary dictionaryWithContentsOfFile:[GetFilePath pathForFile]] objectForKey:@"lists"] allObjects]]];
    [self setListArray: [NSMutableArray arrayWithObjects: @"test", @"test1", @"test2", nil]];

    //define values for drop-down sync interval selector
    [self setSyncIntervalList:[NSMutableArray arrayWithObjects: @"1 minute", @"5 minutes", @"10 minutes", @"30 minutes", @"24 hours", nil]];

    return self;

}

//code for the timer and selector method
- (void) mainViewDidLoad{
NSTimer *timer = [[NSTimer new] autorelease];
    int syncTime = 10;
    timer = [NSTimer scheduledTimerWithTimeInterval: syncTime target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];
}

-(void)targetMethod:(id)sender{

NSLog(@"running timer...");

[self setListArray: [NSMutableArray arrayWithObjects: @"0", @"1", @"2", nil]];
 NSLog(@"%@", listArray);   
}


I think you have two instances of your syncFrontEndPref object instantiated.

If you create a Preference Pane project from the template the File's Owner will be the NSPreferencePane. If you've added another entry for the syncFrontEndPref object, you will be creating a second copy of the object, and mainViewDidLoad won't be called in the second one. The timer won't be triggered for that copy of the object and the listArray won't be updated. Try adding a log statement to the init method. If you see that log statement run twice, you have two copies of the object.

If you do have two copies of the object, I'd suggest removing the copy you added to the xib in IB. Change the class of the File's Owner to your syncFrontEndPref class, and connect your bindings to that object.


Does this look something like your current xib file in IB?

Preference Pane & NSTableView bindings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜