ACDataViews 0.0.5

ACDataViews 0.0.5

测试已测试
Lang语言 Obj-CObjective C
许可证 Apache 2
发布上次发布2015年3月

Dalton Cherry维护。



  • 作者:
  • Dalton Cherry

围绕NSTableView的包装器,使其更易于使用。iOS版本可以在这里找到

TableView 示例

-(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];
}

要求

此框架需要至少OSX 10.7或更高版本。

安装

安装ACDataViews的最佳方法是使用CocoaPods包管理器,因为它提供了灵活的依赖关系管理和简单的安装。

CocoaPods

如果尚未安装,请安装CocoaPods

$ [sudo] gem install cocoapods
$ pod setup

切换到Xcode项目的目录,创建并编辑您的Podfile,并添加ACDataViews

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
platform :osx, '10.7' 
pod 'ACDataViews'

将ACDataViews安装到项目中

$ pod install

从.xcworkspace文件(而不是常规的项目文件)打开Xcode项目

许可证

ACDataViews遵守Apache许可证。

联系方式

Dalton Cherry