29,027
社区成员
发帖
与我相关
我的任务
分享
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSTableCellView *cell = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
NSButton *cell1 = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
CompSameTimeDifSensorModel *comp = dataArray[row];
if ([tableColumn.identifier isEqualToString:@"Selected"]) {
[cell1 setTag:row];
[cell1 setTarget:self];
[cell1 setAction:@selector(cellClick:)];
[cell1 setState:0];
return cell1;
}
else if ([tableColumn.identifier isEqualToString:@"SensorID"]) {
cell.textField.stringValue = comp.SensorID;
}
else if ([tableColumn.identifier isEqualToString:@"MinRecordTime"]) {
NSString *timeStr = [NSString stringWithFormat:@"%f",comp.MinRecordTime];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[timeStr integerValue]/1000.0];
cell.textField.stringValue = [formatter stringFromDate:confromTimesp];
}
else if ([tableColumn.identifier isEqualToString:@"MaxRecordTime"]) {
NSString *timeStr = [NSString stringWithFormat:@"%f",comp.MaxRecordTime];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[timeStr integerValue]/1000.0];
cell.textField.stringValue = [formatter stringFromDate:confromTimesp];
}
return cell;
}
- (void)cellClick:(NSButton *)sender
{
if(sender != nil){
NSButton* cell = (NSButton *)[self.tableView selectedCell];
if([cell state] == 1)
[cell setState:0];
else {
[cell setState:1];
}
NSLog(@"cellClick = %ld",[[self.tableView selectedCell] tag]);
}
}
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row