Re: Loop through NSTableView to set NSCell state
Re: Loop through NSTableView to set NSCell state
- Subject: Re: Loop through NSTableView to set NSCell state
- From: Onar Vikingstad <email@hidden>
- Date: Mon, 15 Apr 2002 00:08:41 +0200
First of all, let me thank you guys for giving me a hand, especially
joar for putting me on the right track. I have now managed to get it to
work, by editing my reloadUserfile method which controls the datasource
for the tableview. Here is what I came up with, and it works great!
enumerator = [users objectEnumerator];
while ( user = [enumerator nextObject] ) {
if( [[user self] isEqualToString:[countObject
objectAtIndex:0]] ) {
NSLog(@"checked user: %@", [user self]);
[record setObject:@"1" forKey:@"check"];
}
}
users is simply just an array of users, so it goes through that and sets
value 1 in check, which is the same identifier in the tableview. I have
to agree with joar that this is a much better approach, and a lot easier
instead of enumerating the cells in tableview which I was doing earlier!
Cocoa newbie learning something new every day... ;)
Kind regards,
Onar Vikingstad
On sxndag, april 14, 2002, at 04:44 , j o a r wrote:
Complying with the MVC pattern you should never need to enumerate over
the cells in the table view - the view is just there do display values,
not provide them. You have "the true" values in your model object.
I would suggest that you set the button state through the table view
delegate methods provided, something like this:
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
if ([[aCell stringValue] isEqualToString:@"someStringValue"]) {
[aCell setNextState]; // If this is the right way to set the state
}
}
Since this method is called once for every displayed cell every time
you reload the table view you will in this way always have the correct
cell state displayed without having to re-display or loop over the
cells any extra times.
j o a r
On Sunday, April 14, 2002, at 04:28 , Onar Vikingstad wrote:
I have been trying to find a way to loop through a NSTableView, row by
row, to check the stringValue of one of the columns up against the
contents of an array I have. If the array-contents match the
stringValue it's just supposed to check the NSButtonCell with
setNextState.
I assume this can be done with using an enumerator, but how? I have
tried fiddling with doing a selectAll on the NSTableView, creating an
selectedRowEnumerator out of that, and then selecting the first row
and start looping through, going down the table row by row. But this
feels like an awfully hard approach, and there must be an easier way!
Hope someone will give me some suggestions or sample code to get me on
the right track here...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.