NSTableView行号

时间:2011-06-20 15:46:15

标签: objective-c cocoa macos nstableview nsarraycontroller

我找不到一种方法来显示行显示的行号。

实际上我有NSArrayControllerNSTableView,其列与NSArrayController绑定。

现在我必须显示行号(可能是DataModel中数据的索引很好),我找不到办法做到这一点。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

在接口构建器中绑定object.value的示例:

// InfoToBind.h

@interface InfoToBind : NSObject {

NSString *kSurname ;
NSString *kName ;  
NSInteger kNumberRow;  
}
@property (nonatomic, retain) NSString * kSurname ;
@property (nonatomic, retain) NSString *kNameKey ;
@property (nonatomic, assign) NSInteger kNumberRow;

// InfoToBind.m

@syntesize ...

// delegate.m

#import "InfoToBind.m


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

InfoToBinb *infoBind = [InfoToBind alloc]init];

images = [[NSMutableArray alloc]init];


//example
InfoDictionary = [[NSDictionary alloc] initWithObjectsAndKeys: 
    @"name", @"Giulio", @"surname", @"Cesare", nil];

NSMutableArray dataSourceArray = [NSMutableArray alloc]init];

infoBind.kName = [InfoDictionary objectForKey:@"Name"];
infoBind.kSurname = [InfoDictionary objectForKey:@"Surname"];

 NSUInteger x;
 for (x = 0; x <= dasourceArray.count; x++) {
    infoBind.kNumberRow ++;
 }
 [dataSourceArray addObject:myClass];


[_tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:dataSourceArray.count]   withAnimation:NSTableViewAnimationSlideLeft];

 }

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{

return [dataSourceArray count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
// Used by bindings on the NSTableCellView's objectValue
NSDictionary *item = [dataSourceArray objectAtIndex:row];
NSLog(@"item is %@", item);

return item;

}

//在CellView中拖动TextField并将其绑定到“表格单元格视图”并添加此值:objectValue.kNumberRow

et voilà