【发布时间】:2011-06-20 15:46:14
【问题描述】:
我找不到让一行显示显示行号的方法。
事实上,我有一个NSArrayController 和一个NSTableView,它们的列绑定到NSArrayController。
现在我必须显示行号(也许 DataModel 中数据的索引很好),但我找不到这样做的方法。
有什么建议吗?
【问题讨论】:
标签: objective-c cocoa macos nstableview nsarraycontroller
我找不到让一行显示显示行号的方法。
事实上,我有一个NSArrayController 和一个NSTableView,它们的列绑定到NSArrayController。
现在我必须显示行号(也许 DataModel 中数据的索引很好),但我找不到这样做的方法。
有什么建议吗?
【问题讨论】:
标签: objective-c cocoa macos nstableview nsarraycontroller
【讨论】:
arangedObjects.@cound.propertyName 这样的NSArrayController` 方法来计算实体的行数,然后将行的列绑定到它包含的数组,其中包含从1 到@count 的数字。你怎么看?
1 到@count 的行,但我说错了BIND。是否可以分配表格的列单元格以显示一些特殊的 NSNumber?
在接口生成器中绑定 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
【讨论】: