• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?


  • Subject: Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?
  • From: Josh Burnett <email@hidden>
  • Date: Thu, 20 Oct 2005 12:19:34 -0400

Tony, when you ran my code, did the ...didChange... notification get sent immediately after you dismissed the alert? Or was there a pause until you clicked somewhere else in the window? I see a pause.

Alright. I've put my code into a simple app that doesn't do anything else. It only has a table and some buttons. The buttons are for adding/removing objects using the NSArrayController, which the table is hooked up to with bindings. I still get the same problem.

Specifically, I add two objects, so I now have two rows in the table. Whenever I try to change the selection, selectionShouldChangeInTableView is called. I've delegated that function to my controller, and from there I create and call the alert.

Now I have two problems:
1. If I choose the button that makes shouldChange return NO, I get a loop, and the alert comes right back. What's up with that?
2. If I choose the option that makes shouldChange return YES, the alert goes away, and I see from my NSLog output that the correct button has indeed been pushed. However, the tableViewSelectionDidChange function hasn't yet been called. It seems to not get called until I click somewhere else on the window. So, my NSLog call from ...didChange... doesn't show up until I click somewhere else in the window. This behavior only shows up when I have the alert in the shouldChange function. Without the alert, the didChange function is called without delay.


I can send along the small XCode project if anyone wants to have a look at it. It's just enough code to exhibit this problem.

Otherwise, here's my delegate methods from my controller:

 - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
	NSLog(@"in selectionShouldChangeInTableView");

	NSAlert * alert = [[NSAlert alloc] init];
	[alert setMessageText:@"Change Selection?"];
	[alert setInformativeText:@"Would you like to change the selection?"];
	[alert addButtonWithTitle:@"Change"];
	[alert addButtonWithTitle:@"Don't Change"];
	int result = [alert runModal];
	if (result == NSAlertFirstButtonReturn) {
		NSLog(@"Change");
		return YES;
	} else {
		NSLog(@"Don't Change");
		return NO;
	}
}

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
	NSLog(@"in tableViewSelectionDidChange:");
	return;
}


That's it. Again, the pause in the debugger output is after the alert is called and I hit the 'change' button.


Thanks,

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
References: 
 >tableViewSelectionDidChange not being called after selectionShouldChangeInTableView? (From: Josh Burnett <email@hidden>)
 >Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView? (From: Josh Burnett <email@hidden>)

  • Prev by Date: Re: NSWindow and NSImageView
  • Next by Date: Re: NSWindow and NSImageView
  • Previous by thread: Re: tableViewSelectionDidChange not being called after selectionShouldChangeInTableView?
  • Next by thread: Core Data Binding with NSArrayController: Replace NSArrayController w/in IB breaks the application
  • Index(es):
    • Date
    • Thread