Reputation: 46533
I am trying to show a custom view containing one NSProgressIndicator
.
I am changing its doubleValue on each timer event but it doesn't get reflected in NSProgressIndicator
. It is always in 0
value.
The code I used is as:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
self.progressViewTextField.stringValue = [NSString stringWithFormat:@"Row: %ld", row];
[self.progressViewBar setDoubleValue: [self.progressViewBar doubleValue]+5];
NSData * archivedView = [NSKeyedArchiver archivedDataWithRootObject:self.progressView];
NSView * myViewCopy = [NSKeyedUnarchiver unarchiveObjectWithData:archivedView];
NSLog(@"progress: %lf", self.progressViewBar.doubleValue);
return myViewCopy;
}
Any help to achieve this is highly appreciated.
Upvotes: 1
Views: 463
Reputation: 437
Please try below code:
@implementation TVAppDelegate{
NSInteger barValue;
}
- (id)init
{
self = [super init];
if (self) {
_progressList = [NSArray arrayWithObjects:@"A",@"B",@"C", nil];
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(timerMethod)
userInfo:nil
repeats:YES];
}
return self;
}
-(void) timerMethod{
barValue+=2;
[self.tableView reloadData];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;{
return self.progressList.count;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSData * archivedView = [NSKeyedArchiver archivedDataWithRootObject:self.progressView];
NSView * myViewCopy =[ NSKeyedUnarchiver unarchiveObjectWithData:archivedView];
[[[myViewCopy subviews] objectAtIndex:1] setDoubleValue: [self.progressViewBar doubleValue]+5];
[[[myViewCopy subviews] objectAtIndex:1] setDoubleValue: barValue];
[[[myViewCopy subviews] objectAtIndex:1] startAnimation:self];
return myViewCopy;
}
Upvotes: 1