2011-06-20 35 views
2

我找不到一行顯示顯示的行號。NSTableView的行號

事實上,我有一個NSArrayController和一個NSTableView其列綁定到NSArrayController

現在我必須顯示行號(也許DataModel中的數據的索引是好的),我找不到方法來做到這一點。

有什麼建議嗎?

回答

0
+0

謝謝您的答覆,我看到了答案,這對我沒有太大的幫助。 我認爲應該使用類似'arangedObjects。@ cound.propertyName'的NSArrayController'方法來計算實體的行,然後將該行的列綁定到包含從'1'到'@ count'編號的數組。 您對此有何看法? – Prooshani

+0

老實說,我會說忘記綁定該行。我的意思是,除非你在實體中追蹤它,否則你甚至會將它綁定到什麼地方?你有沒有真正的鏈接中提到的數據源方法?如果您反對,那麼您將需要做的是將一個屬性添加到您的實體(即rowIndex)。但是你會發現,除非你的數據是非常靜態的,否則很難保持這個屬性與現實同步。 – sosborn

+0

你對我的朋友,我的意思是顯示從'1'行到'@計數',但不正確地說我'BIND'它。 是否可以分配表格的列單元格來顯示一些特殊的NSNumber? – Prooshani

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並將其綁定到 「表格單元格視圖」,並增加該值:objectValue.kNumberRow

et voilà