NSOutlineView的简单使用

NSOutlineView是Cocoa的树形控件,这里介绍它的简单使用。

首先在Xib文件里面拖出控件,然后建立一个委托,把DataSourceDelegate和Delegate绑定该委托。并且在该委托中加入必须的函数,这样数据才能导入进去。

以下是代码实现:

1.保存数据的结构:

#import <Foundation/Foundation.h>

@interface OutlineItem : NSObject
{
    NSString *name;
    NSInteger number;
    NSInteger id_;
    NSString *description;
    BOOL isEnable;
    BOOL isChecked;
    NSImage* logo;
    OutlineItem *parent;
    NSMutableArray *children;
    //NSTreeNode *treeNode;
    
    //1.存储zqdir.可以是一个disk,也可以是一个folder.
    //2.存储sms和contacts时,它就是一个vector.
    void* storage;
}

@property (readonly) NSMutableArray *children;
@property (readwrite, copy) NSString *name;
@property (readwrite) NSInteger number;
@property (readwrite) NSInteger id_;
@property (readwrite) BOOL isEnable; //1.暂时没实现功能.
@property (readwrite) BOOL isChecked;
@property (readwrite,assign) NSImage *logo;
@property (readwrite,assign) void* storage;
@property (readwrite,assign) NSTreeNode *treeNode;

+ (OutlineItem *)rootItem;
+ (OutlineItem *)setRootItem: (OutlineItem *)item;
+ (OutlineItem *)getItem:(NSInteger)id_;

- (void)addChild:(OutlineItem *)item;
- (NSString*)getDescription;
- (NSInteger)numberOfChildren;// Returns -1 for leaf nodes
- (OutlineItem *)childAtIndex:(NSUInteger)n;


@end

#import "OutlineItem.h"

static OutlineItem *root = nil;

@implementation OutlineItem

@synthesize name;
@synthesize number;
@synthesize id_;
@synthesize isEnable;
@synthesize isChecked;
@synthesize logo;
@synthesize children;
@synthesize storage;

-(id)init
{
    [super init];
    
    name = nil;
    description = nil;
    isEn
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值