Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?
Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?
- Subject: Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?
- From: Josh Burnett <email@hidden>
- Date: Wed, 19 Oct 2005 21:47:32 -0400
Very strange. I have a similar NSLog statement in ...didChange..., and
I never see it! The last thing I get is the 'Cancel Changes' note.
I'm going to put together a simple sample app and see if I still have
the same problem. If I don't, then I'll at least know it's something
else. I'll keep you posted.
Perplexed but thankful for your help,
Josh
On Oct 19, 2005, at 9:12 PM, Tony Cate wrote:
I pasted you code into my app and ran it. Here's the debugger output:
2005-10-19 20:05:13.307 A Cooks Books[14843] CFLog (0): CFMessagePort:
bootstrap_register(): failed 1103 (0x44f), port = 0x4603, name = 'A
Cooks Books.ServiceProvider'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2005-10-19 20:05:13.312 A Cooks Books[14843] CFLog (99):
CFMessagePortCreateLocal(): failed to name Mach port (A Cooks
Books.ServiceProvider)
<CFData 0x52837b0 [0xa0728150]>{length = 6, capacity = 6, bytes =
0x000a95b03186}
(gdb) continue
2005-10-19 20:05:30.548 A Cooks Books[14843] in
selectionShouldChangeInTableView
2005-10-19 20:05:30.549 A Cooks Books[14843] info hasn't changed or
drawer isn't open. change to table selection allowed.
2005-10-19 20:05:30.589 A Cooks Books[14843] in
tableViewSelectionDidChange:(NSNotification *)notification
Current language: auto; currently objective-c
(gdb) continue
(gdb) continue
2005-10-19 20:05:47.732 A Cooks Books[14843] in
selectionShouldChangeInTableView
2005-10-19 20:05:47.733 A Cooks Books[14843] info hasn't changed or
drawer isn't open. change to table selection allowed.
(gdb) continue
(gdb) continue
2005-10-19 20:09:55.249 A Cooks Books[14843] in
selectionShouldChangeInTableView
2005-10-19 20:09:55.250 A Cooks Books[14843] info has changed, ask
about changing table selection
(gdb) continue
2005-10-19 20:10:20.363 A Cooks Books[14843] Cancel Changes
2005-10-19 20:10:20.427 A Cooks Books[14843] in
tableViewSelectionDidChange:(NSNotification *)notification
2005-10-19 20:05:47.739 A Cooks Books[14843] in
tableViewSelectionDidChange:(NSNotification *)notification
As you can see, ...DidChange... is called. I only changed the drawer
name and the 'dirty' indicator to make it compile. So, the code is
fine.
Tony
3 Cats And A Mac
http://www.3caam.com
On Oct 19, 2005, at 7:49 PM, Josh Burnett wrote:
That's what I'm doing. Heck, here's the really simplified version I
came up with to check and make sure I'm not going crazy:
When I do this in my table's delegate:
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
NSLog(@"in selectionShouldChangeInTableView");
return YES;
}
Then tableViewSelectionDidChange gets called. But when I do this in
my table's delegate:
(the fields are in a drawer, so first I make sure the drawer's
actually open. transInfoHasChanged is my function that checks... to
see if the transaction's info has changed)
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
NSLog(@"in selectionShouldChangeInTableView");
NSDrawerState state = [detailDrawer state];
if ((state == NSDrawerOpeningState || state == NSDrawerOpenState)
&& [self transInfoHasChanged]) {
NSLog(@"info has changed, ask about changing table
selection");
NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText:@"Transaction Info Has Changed"];
[alert setInformativeText:@"Would you like to save the
transaction, cancel changes, or continue editing?"];
[alert addButtonWithTitle:@"Save"];
[alert addButtonWithTitle:@"Cancel Changes"];
[alert addButtonWithTitle:@"Edit"];
int result = [alert runModal];
if (result == NSAlertFirstButtonReturn) {
NSLog(@"Save");
return YES;
} else if (result == NSAlertSecondButtonReturn) {
NSLog(@"Cancel Changes");
return YES;
} else {
NSLog(@"Continue Editing");
return NO;
}
} else {
NSLog(@"info hasn't changed or drawer isn't open. change to
table selection allowed.");
return YES;
}
}
Then tableViewSelectionDidChange does not get called, regardless of
which button I push, even though selectionShouldChangeInTableView is
returning yes, and the selection does indeed change. I even did one
more try where I didn't even return YES or NO directly from within
the if/else statements. I just added a return YES before the final
bracket of the function. tableViewSelectionDidChange does not get
called.
What gives?
Thanks,
Josh
On Oct 19, 2005, at 8:23 PM, Tony Cate wrote:
selectionShouldChangeInTableView is asking if selected row should
change. Once the alert has run, handle the commit edit decision and
then return yes.
On Oct 19, 2005, at 2:55 PM, Josh Burnett wrote:
Hi all,
I'm working on an application that has a table where each row
corresponds to an object, and a drawer that has the selected
object's info laid out in more detail. Rather than having the
values directly bound through an NSArrayController, I would rather
have the changes wait until the user explicitly clicks a button.
That part I've got so far.
If the user begins editing on object's details, and then goes to
switch to a different object without saving or canceling the edits
in progress, I want an alert dialog to pop up and ask it the user
wants to record the changes, discard them, or continue editing the
object. At the moment, I've got this implemented through the
table's selectionShouldChangeInTableView: delegate method. Without
the alert, everything behaves as expected.
Here's snag #1: when selectionShouldChangeInTableView: returns NO,
the table in question issues its action, acting as if the original
row had been re-selected, rather than no change in selection having
occurred. This throws everything off, because it resets the edited
detail fields to the objects currently saved values, not their
potentially edited states.
First, is there a way to make this not happen? It would make my
life easier if the table just acted like nothing had happened.
Then I wouldn't have to worry about the next problem.
As an attempted workaround, I disassociated the table from its
action and called it in the tableViewSelectionDidChange delegate
method. This seemed alright, until I put the aforementioned alert
in the selectionShouldChangeInTableView: delegate method. Without
the alert, if shouldChange returns YES, the didChange method gets
called. With the alert, the didChange method does not get called,
even if the shouldChange method returns YES. This makes no sense
to me.
What's going on here? Any suggestions or ideas? I can post the
code if anyone wants to see it, as it's not that long.
Thanks a lot,
Josh
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden