访问NSTableViewHeader的NSTableHeaderCell以进行自定义

时间:2013-08-30 11:45:22

标签: objective-c cocoa nstableview nstableviewcell nstableheaderview

根据NSTableHeaderView类引用,NSTableHeaderView使用NSTableHeaderCell类来实现其用户界面。

  

NSTableHeaderView使用NSTableHeaderCell来实现其用户界面。

NSTableHeaderView Class Reference

好的,现在我将NSTableHeaderCell子类化并进行必要的更改,但如何将自定义NSTableHeaderCell分配给NSTableHeaderView?

1 个答案:

答案 0 :(得分:0)

    Try like this:-

    #import <Cocoa/Cocoa.h>

    @interface customHeaderCell : NSTableHeaderCell
    {

    }

    @end

    #import "customHeaderCell.h"

    @implementation customHeaderCell

    -(id)initTextCell:(NSString *)aString
    {
   if([aString isEqualToString:@"yourHeaderCell"])
{
    // do your stuff here;
}
        return [super initTextCell:aString];
    }

    @end


    Now in other class wherever your table view you are using write the following the code:-

    -(IBAction)addData:(id)sender
    {
        for (NSTableColumn *col in [tableView tableColumns])
        {
            customHeader=[[customHeaderCell alloc]initTextCell:[col identifier]];

        }

    }