Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Small problem with NSTableView delegate

 
   Mac (Home) -> Programmer Help RSS
Next:  desperate housewives  
Author Message
Jim

External


Since: Apr 10, 2007
Posts: 38



(Msg. 1) Posted: Mon Nov 24, 2008 11:30 am
Post subject: Small problem with NSTableView delegate
Archived from groups: comp>sys>mac>programmer>help (more info?)

I'm doing a small hack project to try to learn a bit about NSTableViews.

I've created a window with one such, set its dataSource to an object
containing an NSMutableArray, then tried to set up the delegates. It's
mostly working fine.

The only one I'm having a problem with is:


- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex


It gets called fine, but no matter which row is doubleclicked rowIndex is
always set to -1.

If I grab the value by using [aTableView selectedRow] then I get the correct
(or rather, expected) value.

Any ideas what I may have done wrong? Like I say, all other implemented
delegates appear to be working fine.

Many thanks.

Jim
--
http://www.ursaMinorBeta.co.uk http://twitter.com/GreyAreaUK
"My idea of a fair fight: I'm in a main battle tank. My opponent
is 3 miles away, on a hill top, armed with a pistol."
- Dave the Australian.
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 2) Posted: Mon Nov 24, 2008 4:52 pm
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <slrngil41u.l8m.jim.TakeThisOut@wotan.magrathea.local>,
Jim <jim.TakeThisOut@magrathea.plus.com> wrote:

> I'm doing a small hack project to try to learn a bit about NSTableViews.
>
> I've created a window with one such, set its dataSource to an object
> containing an NSMutableArray, then tried to set up the delegates. It's
> mostly working fine.
>
> The only one I'm having a problem with is:
>
>
> - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
> forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
>
>
> It gets called fine, but no matter which row is doubleclicked rowIndex is
> always set to -1.
>
> If I grab the value by using [aTableView selectedRow] then I get the correct
> (or rather, expected) value.
>
> Any ideas what I may have done wrong? Like I say, all other implemented
> delegates appear to be working fine.

Part of what you've done wrong is mixed terminology in your request for
help, which may be why nearly 12 hours later there's no response (at
least on this server). There are two conceptually distinct object
related to table views: the data source and the delegate. They may, of
course, be the same object but they respond to different messages and
are thus responsible for different bits of user experience.

Beyond that what I'm finding confusing is *when* the data source method
you reference above is being invoked as compared to when you expect it
to be invoked. The method above is generally only meaningful when
editing has been completed, but double-clicking would *start* editing
and a row of -1 is clearly out of range so I'd think your sanity
checking in the process of responding to the set would just ignore such
invocations.

--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
Back to top
Login to vote
jim

External


Since: Dec 23, 2007
Posts: 7



(Msg. 3) Posted: Tue Nov 25, 2008 7:10 am
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Gregory Weston <uce RemoveThis @splook.com> wrote:

<snip>

Looks like I'm confusing datasources and delegates. Sorry about that - I
assume it's datasources I'm actually have an issue with.

> Beyond that what I'm finding confusing is *when* the data source method
> you reference above is being invoked as compared to when you expect it
> to be invoked. The method above is generally only meaningful when
> editing has been completed, but double-clicking would *start* editing
> and a row of -1 is clearly out of range so I'd think your sanity
> checking in the process of responding to the set would just ignore such
> invocations.

The actual code in question is simply this:

-(void)tableView:(NSTableView*)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(int)row

{
NSLog(@"selectedRow = %d", [aTableView selectedRow]);
NSLog(@"Attempting to alter item number %d", row);

[array replaceObjectAtIndex:[aTableView selectedRow]
withObject:anObject];

}

where 'array' is an NSMutableArray.


The confusing thing (to me) is that the example I based it on (from
Cocoadev) used the 'row' variable to alter the array.

The above code _seems_ to work, but I'll take another look at it and
work through some other examples.

Many thanks.

Jim
--
"My idea of a fair fight: I'm in a main battle tank. My opponent
is 3 miles away, on a hill top, armed with a pistol."
- Dave the Australian.
http://www.UrsaMinorBeta.co.uk http://twitter.com/GreyAreaUK
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 4) Posted: Tue Nov 25, 2008 9:58 am
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1iqy8tp.1nzy7tt188r0w0N%jim@magrathea.plus.com>,
jim.DeleteThis@magrathea.plus.com (jim) wrote:

> Gregory Weston <uce.DeleteThis@splook.com> wrote:
>
> <snip>
>
> Looks like I'm confusing datasources and delegates. Sorry about that - I
> assume it's datasources I'm actually have an issue with.
>
> > Beyond that what I'm finding confusing is *when* the data source method
> > you reference above is being invoked as compared to when you expect it
> > to be invoked. The method above is generally only meaningful when
> > editing has been completed, but double-clicking would *start* editing
> > and a row of -1 is clearly out of range so I'd think your sanity
> > checking in the process of responding to the set would just ignore such
> > invocations.
>
> The actual code in question is simply this:
>
> -(void)tableView:(NSTableView*)aTableView setObjectValue:(id)anObject
> forTableColumn:(NSTableColumn *)aTableColumn row:(int)row
>
> {
> NSLog(@"selectedRow = %d", [aTableView selectedRow]);
> NSLog(@"Attempting to alter item number %d", row);
>
> [array replaceObjectAtIndex:[aTableView selectedRow]
> withObject:anObject];
>
> }
>
> where 'array' is an NSMutableArray.
>
>
> The confusing thing (to me) is that the example I based it on (from
> Cocoadev) used the 'row' variable to alter the array.
>
> The above code _seems_ to work, but I'll take another look at it and
> work through some other examples.
>
> Many thanks.
>
> Jim

I'm going to claim that something's up elsewhere in your code. I'm
having no luck finding any documented circumstance under which the
setter is invoked at the start of editing or under which it's invoked
with a row index of -1. I just threw together the most trivial table
editing sample and at least by default there's no such behavior.

Here's the implementation of my data source:

- (void)awakeFromNib
{
a = [[NSMutableArray alloc] initWithObjects:@"a", @"b", @"c", nil];
}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [a count];
}

- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
NSLog(@"Getting row %d", rowIndex);
return [a objectAtIndex:rowIndex];
}

- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
NSLog(@"Setting row %d to %@", rowIndex, anObject);
[a replaceObjectAtIndex:rowIndex withObject:anObject];
}

--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
Back to top
Login to vote
Jim

External


Since: Apr 10, 2007
Posts: 38



(Msg. 5) Posted: Tue Nov 25, 2008 3:23 pm
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2008-11-25, Gregory Weston <uce RemoveThis @splook.com> wrote:
>
> I'm going to claim that something's up elsewhere in your code.

Almost certainly, yes Smile

> I'm
> having no luck finding any documented circumstance under which the
> setter is invoked at the start of editing or under which it's invoked
> with a row index of -1.

The 'start of editing' bit was certainly me just mistaking what it does -
you're correct that it gets invoked at the _end_ of editing. I see that now.

The row index of -1 is still puzzling, but I'll do what you did and throw
together a small test app and see what I get. Hopefully I'll be able to
figure out what it is I've done wrong.

The fact that it's currently working (or, at least, appears to) is neither
here nor there to me, as _something_ isn't right.

I'll puzzle it out.

Many thanks for your time.

Jim
--
http://www.ursaMinorBeta.co.uk http://twitter.com/GreyAreaUK
"My idea of a fair fight: I'm in a main battle tank. My opponent
is 3 miles away, on a hill top, armed with a pistol."
- Dave the Australian.
Back to top
Login to vote
jim

External


Since: Dec 23, 2007
Posts: 7



(Msg. 6) Posted: Thu Nov 27, 2008 7:06 am
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Gregory Weston <uce.DeleteThis@splook.com> wrote:

> I'm going to claim that something's up elsewhere in your code.

And indeeed there was.

For some reason - I blame the government - I'd added a '[aTableView
reloadData]' line in my

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

method, which was (a) completely superfluous, and (b) downright wrong.
It must have reset the 'row' value, hence 'row' being -1 but
'selectedRow' being correct.

Stupid, stupid, stupid of me. At least I founf it though. It was
starting to drive me slightly mad.

Jim
--
"My idea of a fair fight: I'm in a main battle tank. My opponent
is 3 miles away, on a hill top, armed with a pistol."
- Dave the Australian.
http://www.UrsaMinorBeta.co.uk http://twitter.com/GreyAreaUK
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 7) Posted: Thu Nov 27, 2008 11:03 am
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1ir1y6k.1k93et415dsg2dN%jim@magrathea.plus.com>,
jim.RemoveThis@magrathea.plus.com (jim) wrote:

> Gregory Weston <uce.RemoveThis@splook.com> wrote:
>
> > I'm going to claim that something's up elsewhere in your code.
>
> And indeeed there was.
>
> For some reason - I blame the government - I'd added a '[aTableView
> reloadData]' line in my
>
> -(id)tableView:(NSTableView*)aTableView
> objectValueForTableColumn:(NSTableColumn*)aTableColumn row:(int)row
>
> method, which was (a) completely superfluous, and (b) downright wrong.
> It must have reset the 'row' value, hence 'row' being -1 but
> 'selectedRow' being correct.
>
> Stupid, stupid, stupid of me. At least I founf it though. It was
> starting to drive me slightly mad.
>
> Jim

Happens to everyone. Somewhere along the line we all do

if(bargle);
{
// stuff we don't expect to execute every time.
}

Glad to hear you found it.

--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
Back to top
Login to vote
Jim

External


Since: Apr 12, 2007
Posts: 9



(Msg. 8) Posted: Thu Nov 27, 2008 5:21 pm
Post subject: Re: Small problem with NSTableView delegate [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Gregory Weston <uce.TakeThisOut@splook.com> wrote:

> Glad to hear you found it.

[self LART];

Jim
--
'Cloverfield' in nine words: "What is it?!" "We're gonna die!" BOOM!
Roll credits.

http://www.ursaminorbeta.co.uk http://twitter.com/greyareauk
Back to top
Login to vote
Display posts from previous:   
Related Topics:
seeking an example for NSOutlineView and NSTableView - Hi, I am newbie learning cocoa programming on mac os x. I am having trouble understanding the NSOutlineView. Can somebody point me to an example for the same ( which has step by step instructions)? Also, can somebody point me to an example for..

NSTableView selection and NSArrayController Q - I have two NSTableviews each bound to their own NSArrayControllers. The tables sit side by side in a window and are populated simultaneously via their respective controllers. That works all well and good. The problem I have is that the first row in each...

Kicking bindings to refresh a NSTableView - Hoping one of you might have come across this before and can provide some suggestions: I have a minimal app with an NSTableView whose NSTableColumns have "value" bindings to an NSArrayController's arrangedObjects. The NSArrayController's &q...

creating a window delegate - Hillegass chapter 6 - Guys/Gals, I am trying to complete the challenge in Hillegas book, chapter 6. I need to create a delegate to a window that constraints its resinzing. I have the following code: // AppController.h // Delegate Try #import <Cocoa/Cocoa.h> @interface...

Some small (?) Carbon troubles - Hey, Im trying to use carbon to make a small app for an image gallery im working on. All this app needs to do is watch for new images to appear in a directory, then possibly rotate them and create a thumbnail, then move everything to another directory.....
       Mac (Home) -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact