views:

31

answers:

1

Hi all. A few days ago I posted a problem with using checkboxes in nstableview (old question). Peter Hosey helped me, but I am still unable to get this to work. I seem to be doing something very wrong with implementing a button that shoud be straightforward. I have a tableview with three fields; bool, text, and text. The values of each column is binded to my arraycontroller. This works fine upon start and the table fills in nicely and all checkboxes are set to on. The application crashes when I try to click any checkbox and set it to off. The value of the checkbox is a boolean attribute of an object and the click on the checkbox should change the value of the attribute and store it. I thought I could do that using KVC where the objects are stored in a nsmutablearray (I am not using Core Data), and defining:

@property(readwrite) BOOL doSync; //(interface)
@dynamic doSync; // implementation

I am sure I am doing something fundamentally wrong ,but i am unable to find the bug even after reading everything I can come over of literature online or in books. How do I set the value of the doSync attribute after clicking my checkbox? I ran the program with the debugger and the top part of the crash report looks like this:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000060 Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 com.apple.CoreData 0x00007fff8607b73b _propertyAtIndexForEntityDescription + 11 1 com.apple.CoreData 0x00007fff860b83c2 -[NSManagedObject validateValue:forKey:error:] + 98 2 com.apple.Foundation 0x00007fff880ea3cf -[NSObject(NSKeyValueCoding) validateValue:forKeyPath:error:] + 254 3 com.apple.AppKit 0x00007fff83d4ec01 -[NSBinder _setValue:forKeyPath:ofObject:mode:validateImmediately:raisesForNotApplicableKeys:error:] + 196 4 com.apple.AppKit 0x00007fff83df7855 -[NSBinder setValue:forBinding:atIndex:error:] + 492 5 com.apple.AppKit 0x00007fff83d66b33 -[_NSValueBinderPlugin applyObjectValue:forBinding:operation:needToRunAlert:error:] + 423 6 com.apple.AppKit 0x00007fff84140ec5 -[NSValueBinder _applyObjectValue:forBinding:canRecoverFromErrors:handleErrors:typeOfAlert:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:] + 116 7 com.apple.AppKit 0x00007fff84140d2c -[NSValueBinder applyDisplayedValueHandleErrors:typeOfAlert:canRecoverFromErrors:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:] + 567 8 com.apple.AppKit 0x00007fff83d66556 -[NSValueBinder performAction:] + 300 9 com.apple.AppKit 0x00007fff83d663e3 -[_NSBindingAdaptor _objectDidTriggerAction:bindingAdaptor:] + 136 10 com.apple.AppKit 0x00007fff83d6632d -[_NSBindingAdaptor objectDidTriggerAction:] + 218 11 com.apple.AppKit 0x00007fff83cda092 -[NSControl sendAction:to:] + 63

I would appreciate any links to examples I may look at, and comments on to how I may solve this problem. I thank you for your patience and hope that some of you may help.

Best, Trond Kristiansen

A: 

It turns out that I did not properly access my object and therefore cause my setter to crash. In addition, I think I have been pleasently ignorant of the difference between using a datasource and bindings using KVC and have mixed them. So I started over again and I removed my checkboxes, and created a new column called checkbox. Then I created a subclass of NSCell which controls and draws each row according to the objects value I receive using KVC. Now the setter also works nicely. Thanks for all help.

Trond Kristiansen