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 20:49:27 -0400
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