How can I detect which tableview sent the notification?

Hello friends,

I have two table views connected to the very same “on tableViewSelectionDidChange_(aNotification)” handler.

Question:

How can I detect which of the two table views was clicked?

I can get this:

<NSTableView: 0x102c28370>

When I have a line “log aNotification”.

But I don’t know how to insert this info in an “if” block to run different routines for each table view.

Thanks for any help.

Just assign IBOutlets to your two tables and use those names in your if statement, for example if your outlets were table1 and table2, you could just write:

if aNotification’s object is table1 then
–do something with table1
else
–do something with table2
end if

Ric

Hi rdelmar!

Thanks for posting.

Your lines result in:



[<NSTableView 0x103110170> valueForUndefinedKey:]: this class is not key value coding-compliant for the key object.
2011-12-15 01:45:34.867 idanfe[20811:707] (
	0   CoreFoundation                      0x00007fff8f86d206 __exceptionPreprocess + 198
	1   libobjc.A.dylib                     0x00007fff90b85d5e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff8f8f7449 -[NSException raise] + 9
	3   Foundation                          0x00007fff943a0783 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 240
	4   Foundation                          0x00007fff942d7462 _NSGetUsingKeyValueGetter + 108
	5   Foundation                          0x00007fff942d73e9 -[NSObject(NSKeyValueCoding) valueForKey:] + 392
	6   AppleScriptObjC                     0x00007fff8ed60c39 objcInstanceForSpecifier + 1069
	7   AppleScriptObjC                     0x00007fff8ed644c1 BASendProc + 513
	8   AppleScript                         0x0000000102e23c1f _Z13ComponentSendPK6AEDescPS_ii + 498
	9   AppleScript                         0x0000000102e32695 _ZN15TUASApplication4SendEP25TStackFrame_UASRemoteSendP6AEDescS3_hhh + 2563
	10  AppleScript                         0x0000000102e4f8fd _Z13UASRemoteSendhhhhhPh + 409
	11  AppleScript                         0x0000000102e49036 _Z16UASRemoteGetDataP15TUASObjectAliasP15TUASApplicationP19TUASClassIdentifierPh + 833
	12  AppleScript                         0x0000000102e5b915 _Z25UASGetDataNoCircularitieshP19TUASClassIdentifier + 156
	13  AppleScript                         0x0000000102e5b985 _Z10UASGetDatahP19TUASClassIdentifier + 57
	14  AppleScript                         0x0000000102e33f44 _Z29UASObjectAlias_BinaryOperatorPFvvEj24TUASSupportsOperatorFlag + 136
	15  AppleScript                         0x0000000102e35251 _Z7BCEqualv + 220
	16  AppleScript                         0x0000000102e36e87 _Z11UASExecute1v + 356
	17  AppleScript                         0x0000000102e0c2af _Z14ASExecuteEventPK6AEDescjiPj + 688
	18  AppleScript                         0x0000000102e0628e AppleScriptComponent + 1678
	19  OpenScripting                       0x00007fff8e5500c0 OSAExecuteEvent + 63
	20  AppleScriptObjC                     0x00007fff8ed5d9ba +[BAObjectProto invokeScriptHandler:forObject:args:error:] + 243
	21  AppleScriptObjC                     0x00007fff8ed5dc60 -[BAObjectProto invokeScriptHandler:args:error:] + 93
	22  AppleScriptObjC                     0x00007fff8ed5ea36 -[BAObjectProto forwardInvocation:] + 368
	23  CoreFoundation                      0x00007fff8f85a234 ___forwarding___ + 756
	24  CoreFoundation                      0x00007fff8f859ec8 _CF_forwarding_prep_0 + 232
	25  CoreFoundation                      0x00007fff8f85c99d -[NSObject performSelector:withObject:] + 61
	26  AppKit                              0x00007fff97835ed4 -[NSApplication sendAction:to:from:] + 139
	27  AppKit                              0x00007fff97835e06 -[NSControl sendAction:to:] + 88
	28  AppKit                              0x00007fff9789c59a -[NSTableView _sendAction:to:row:column:] + 87
	29  AppKit                              0x00007fff97899458 -[NSTableView mouseDown:] + 6122
	30  AppKit                              0x00007fff977fe860 -[NSWindow sendEvent:] + 6306
	31  AppKit                              0x00007fff97797303 -[NSApplication sendEvent:] + 5593
	32  AppKit                              0x00007fff9772d2d6 -[NSApplication run] + 555
	33  AppKit                              0x00007fff979ab990 NSApplicationMain + 867
	34  idanfe                              0x000000010000118a main + 74
	35  idanfe                              0x0000000100001134 start + 52
)


Any clues?

I can’t tell without seeing the code. Post the code where you implemented my lines.

Ric

Thanks my friend.

This is the full method:


on tableViewSelectionDidChange_(aNotification)
        
        log "table view selection has changed..."
        
        tell theArrayController to set theSel to selectedObjects() as list
        set xmlPathAsUrlString to convertPath_to_Url_(theXMLPaths of  item 1 of theSel)
        set pdfPathAsString to convertPath_to_Url_(thePDFPaths of item 1 of theSel)
        renderPdfOfSelectedRow_(xmlPathAsUrlString,pdfPathAsString)
         
         if aNotification's object is the_invoices_table then
             log "the_invoices_table"
         else 
             log "the_folders_table"
         end if
         
    end tableViewSelectionDidChange_

I pasted your code into my app and commented out the middle group of lines (between the first log statement and the if block) since I have no way to test those – the remaining code worked fine. Try commenting those lines out and see what happens.

Ric

I tried commenting the same lines, leaving just:



if aNotification's object is the_invoices_table then
             log "the_invoices_table"
         else 
             log "the_folders_table"
end if


I still get the same errors…

Please note I am using an array controller …

Did you make that method, tableViewSelectionDidChange_(aNotification), an IBAction for your table? It looks like from the error message that you are trying to get the value of “object” from the table view. I reread your first post, and it looks like that’s what you did. That’a not how delegate methods like “tableViewSelectionDidChange:” work. You don’t make this the action for your table view. You make your script the delegate of your two table views (from the connections pane in the inspector in IB), and then this method gets called by the table view when the selection changes.

Ric

I clicked in the little cube for my appDelegate then → Connections inspector → received actions , connected “tableViewSelectionDidChange:” to both tables.

That’s it.

Should I have done it differently?

The code works. I just can’t write further code to distinguish the tables.

If I just could convert “<NSTableView 0x103110170>” to some usable data…

Thanks my friend!

I solved it.

I clicked on the table view, then connections → Outlets and linked “delegate” to my app delegates little cube.

Now it works.

Hi,

<NSTableView 0x103110170> is usable data because it’s an object specifier.
If you have defined

property myTableView : missing value

and have connected the property in Interface Builder, you can identify the object
in the delegate method with with

if (aNotification's |object|() isEqualTo_(myTableView) then
-- do something with myTableView
end if

Yes, as I said in my last post, you don’t connect delegate methods that way. You should delete those connections.

This is all you need to do for delegate methods, as far as connections are concerned.

Ric

Thanks rDelmar and Stefank.

You have been very helpful my friends…