NSTableView searching and predicates
NSTableView searching and predicates
- Subject: NSTableView searching and predicates
- From: Daniel Wambold <email@hidden>
- Date: Fri, 03 Aug 2007 09:49:48 -0400
I am afraid I may have overcomplicated my question, as I have been
working on this problem for a while now. Here's the basic trouble I'm
having with my NSTableView and search field:
1. I have an NSTableView populated by an NSArrayController. This is,
in turn, fed by CoreData and an XCDataModel.
2. I have an IB-placed search box which invokes a method
myEventSearch:(id)sender with live searching (i.e.: when the user
pauses while typing). (I have implemented this method because I want
to be able to modify searches to include a "paid item is checked"
conditional if the user chooses to hide items that are marked paid.
It's not shown here for simplicity, but this is the actual code I'm
using for debugging, and this doesn't work either.)
myEventSearch: takes the NSString from the search box and builds an
NSPredicate with it:
-(void) myEventSearch:(id)sender
{
NSString *mySearchString;
if ([sender stringValue] == nil)
{
mySearchString = [[[NSString alloc] initWithString:@""] autorelease];
}
else
{
mySearchString = [[[NSString alloc] initWithString:[sender
stringValue]] autorelease];
}
NSPredicate *myFilterPredicate = [[[NSPredicate alloc] init]
autorelease];
myFilterPredicate = [NSPredicate predicateWithFormat:@"%@ IN[cd]
myEvent || %@ IN[cd] myNotes", mySearchString, mySearchString];
[self setFilterPredicate:myFilterPredicate];
[self rearrangeObjects];
}
Typing in the search field yields the proper results. However,
clicking on an entry causes a crash most of the time. Listening for
NSTableViewSelectionDidChangeNotifications and logging the
selectionIndex shows occasional erratic behavior, with the value
returning out of order occasionally or even as a very large integer
like 2147483647. Apparently, the underlying collection of objects is
not properly rearranged in, perhaps, the implementation of
NSTableView, but somewhere, the program is running into a problem
with this implementation. Below is the GDB call stack (is that what
this is called?) at the crash. Any thoughts would be greatly
appreciated. My earlier post represented an attempt to work around
this problem, but I am sure someone has encountered this difficulty
and fixed it in a more elegant way than what I've been hammering away
at. Thanks again for your time and advice!
-Dan
#0 0xfffeff18 in objc_msgSend_rtp
#1 0x939c9e34 in _NSValuesAreEqual
#2 0x93c644d0 in -[NSTableBinder
tableView:didChangeToSelectedRowIndexes:]
#3 0x93c54700 in -[_NSBindingAdaptor
tableView:didChangeToSelectedRowIndexes:]
#4 0x93845ec4 in -[NSTableView _enableSelectionPostingAndPost]
#5 0x9384a1b8 in -[NSTableView
_doSelectIndexes:byExtendingSelection:indexType:funnelThroughSingleIndex
Version:]
#6 0x9385ba0c in -[NSTableView selectRow:byExtendingSelection:]
#7 0x9390e2d4 in -[NSTableView keyDown:]
#8 0x937fafa0 in -[NSWindow sendEvent:]
#9 0x937a38d4 in -[NSApplication sendEvent:]
#10 0x9379ad10 in -[NSApplication run]
#11 0x9388b87c in NSApplicationMain
#12 0x00011fa8 in main at main.m:13
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden