views:

29

answers:

1

Hi all,

I have a simple question:

How to show serial nos. or (row no. + 1) in a table column using cocoa bindings and array controller?

I have made an application using cocoa bindings and array controller, in which I am displaying names of certain persons in a table column. The class from which I am displaying is named as: Person. Now I want to show serial nos. in first column, such that list gets displayed like this :

1 / John

2 / Peter

It is very easy to do if I use data source method:

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

I just need to return something like this :

return [NSString stringWithFormat:@"%d",rowIndex+1];

but I am not getting how to do this via cocoa binding and array controller.

Can anyone suggest me solution for it?

Thanks,

Miraaj

+1  A: 

One way you can do this is to actually mix using bindings and a data source with the same table view. Go ahead and hook up bindings for the rest of your table columns, but leave the one you want to display the indices in unbound. Then, just implement the table data source as normal for just that one column. It should only ever ask you for data fir Amy unbound columns, and just use the bound data for the rest.

Brian Webster
ok... thanx for your reply :)
Miraaj