2

I can't find a way to make a row to show the displayed row's number.

In fact I have an NSArrayController and an NSTableView whose columns are bound to the NSArrayController.

Now I have to show the row number (maybe index of the data in DataModel is fine) and I can't find a way to do this.

Any suggestions?

Prooshani
  • 534
  • 7
  • 20

2 Answers2

0

example with binding object.value in interface builder :

// 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;

}

//drag a TextField in CellView and bind it to "table cell view" and add this value: objectValue.kNumberRow

et voilà

sundsx
  • 588
  • 9
  • 27
0

Check out this answer: Displaying row index in an NSTableView bound to NSArrayController

Community
  • 1
  • 1
sosborn
  • 14,676
  • 2
  • 42
  • 46
  • Thank you for your response, I saw that answer and it's not helped me as much. I think it would be done counting the entity's rows using NSArrayController` methods like `arangedObjects.@cound.propertyName` and then bind the row's column to the array that it's contained with number from `1` to the `@count` number. What do you think about it? – Prooshani Jun 21 '11 at 05:52
  • Honestly I would say forget binding that row. I mean, what would you even bind it to unless you track it in your Entity? Did you actually the datasource method mentioned in that link? If you are opposed to that then what you will have to do is add a property to your entity (i.e. rowIndex). But you are going to find that it is difficult to keep that property in sync with reality, unless your data is very static. – sosborn Jun 21 '11 at 06:46
  • you right my friend, I mean to show the row from `1` to `@count` but incorrectly I said `BIND` it. is it possible to assign the Table's column Cells to show some special NSNumber? – Prooshani Jun 21 '11 at 07:05
  • Yes it is possible. All you have to do is following the instructions on the answer that I linked to. If you look at the accepted answer the original poster leaves a comment explaining how to do this. Why do you not want to try that? – sosborn Jun 21 '11 at 07:32
  • Can I reopen this question? I need to display the index of an object in an ordered Core Data relation, which is using the NSOrderedSet class. Contrary to the question quoted, the # I want to display is not the display index, but the object index in the relation. They are often the same, but not always, for example when filtering out some lines. – Jean-Denis Muys Nov 16 '11 at 13:46
  • Open a new question if it is different from what the OP asked. – sosborn Nov 16 '11 at 22:38