TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | Apache 2 |
ReleasedLast Release | Mar 2015 |
Maintained by Dalton Cherry.
Wrapper around NSTableView to make simpler to use. iOS version can be found here
-(void)awakeFromNib
{
//first we create the datasource object
self.dataSource = [[ACTableSource alloc] init];
self.dataSource.delegate = self;
self.tableView.dataSource = self.dataSource;
self.tableView.delegate = self.dataSource;
self.time = [NSMutableArray new];
self.source = [NSMutableArray new];
self.destination = [NSMutableArray new];
self.protocol = [NSMutableArray new];
//bind the datasource to our arrays and to the tableview
[self.dataSource bindArrays:@[self.time,self.source,self.destination,self.protocol]
toTableView:self.tableView];
//test data
for(int i = 0; i < 10; i++)
{
[self.time addObject:@"random time"];
[self.source addObject:@"random src"];
[self.destination addObject:@"random dest"];
[self.protocol addObject:@"random protocol"];
}
[self.tableView reloadData];
}
//then implement this delegate to map the object to cell associates.
-(Class)classForObject:(id)object
{
if([object isKindOfClass:[NSString class]])
return [TextTableViewCell class];
//any kind of custom object could be mapped here...
return nil;
}
//then in a subclass of ACTableViewCell (TextTableViewCell for example):
+(CGFloat)tableView:(NSTableView*)tableView rowHeightForObject:(id)object
{
return 22; //any size you need
}
//your main init method to override and setup and add your custom views (if you don't want to use a nib).
-(id)initWithIdentifier:(NSString*)identifier
{
if(self = [super initWithIdentifier:identifier])
{
self.textLabel = [[NSTextField alloc] init];
[self.textLabel setBordered:NO];
[self.textLabel setBezeled:NO];
self.textLabel.backgroundColor = [NSColor clearColor];
[self addSubview:self.textLabel];
}
return self;
}
//again, only need this if you don't use a nib.
-(void)layout
{
[super layout];
self.textLabel.frame = NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height);
}
//update the values with your objects values (object is an NSString in this example)
-(void)setObject:(id)object
{
self.textLabel.stringValue = object;
}
//this is updates the cell when it is selected.
-(void)setSelected:(BOOL)selected
{
if(selected)
self.textLabel.textColor = [NSColor whiteColor];
else
self.textLabel.textColor = [NSColor blackColor];
}
This framework requires at least OSX 10.7 or above.
The recommended approach for installing ACDataViews is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation.
via CocoaPods
Install CocoaPods if not already available:
$ [sudo] gem install cocoapods
$ pod setup
Change to the directory of your Xcode project, and Create and Edit your Podfile and add ACDataViews:
$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
platform :osx, '10.7'
pod 'ACDataViews'
Install into your project:
$ pod install
Open your project in Xcode from the .xcworkspace file (not the usual project file)
ACDataViews is license under the Apache License.