automatic ref counting - NSOutlineView:child:ofItem throws EXC_BAD_ACCESS / loss of object "Item" -
my outlineview crashes exc_bad_access when expand column width - or scroll up/down.
outlineview has controller 4 basic methods:
- (nsinteger)outlineview:(nsoutlineview *)outlineview numberofchildrenofitem:(id)item - (bool)outlineview:(nsoutlineview *)outlineview isitemexpandable:(id)item - (id)outlineview:(nsoutlineview *)outlineview child:(nsinteger)index ofitem:(id)item - (id)outlineview:(nsoutlineview *)outlineview objectvaluefortablecolumn:(nstablecolumn *)tablecolumn byitem:(id)item
my app starts displaying contents without problem ,but @ point resizing columns or scrolling, crashes @ :
- (id)outlineview:(nsoutlineview *)outlineview objectvaluefortablecolumn:(nstablecolumn *)tablecolumn byitem:(id)item
then, item nil. problem. looks arc issue, in controller, own object returned outlineview, either using method
myobject=[nodeobject new];
or
myobject =[node copy]; // node != nil checked before
what's important too: return item directly object. assure outlineview gets non nil objects outlineview:child:ofitem :
- (id)outlineview:(nsoutlineview *)outlineview objectvaluefortablecolumn:(nstablecolumn *)tablecolumn byitem:(id)item { return item; }
any suggestions @ solve issue welcome !
full samplecode here:
#import "outlinecontroller.h" @implementation outlinecontroller { } // // items of type hierarchy ! // - (nsinteger)outlineview:(nsoutlineview *)outlineview numberofchildrenofitem:(id)item { nsinteger result=0; id kvalue=[item anobject]; if (!item) { result = [[delegate dictdatasource] count]; } else { if ( [kvalue iskindofclass:[nsdictionary class]] || [kvalue iskindofclass:[nsarray class]]) result=[kvalue count]; } nslog(@"nbr of childs %ld",(long)result); return result; } - (bool)outlineview:(nsoutlineview *)outlineview isitemexpandable:(id)item { bool result=no; id kvalue=[item anobject]; if (!item) { result = [[delegate dictdatasource] count] > 0 ? yes:no; } else { if ( [kvalue iskindofclass:[nsdictionary class]] || [kvalue iskindofclass:[nsarray class]]) result=yes; } nslog(@"expandable %d",result); return result; } // // place items created here ! // - (id)outlineview:(nsoutlineview *)outlineview child:(nsinteger)index ofitem:(id)item { id oneobject; hierarchy *hchy; // // root of type dictionary, , take keys "index" if ( !item ) { hchy = [hierarchy new]; [hchy setcomesfromdict:[delegate dictdatasource]]; [hchy setkey:[[[hchy comesfromdict] allkeys ] objectatindex:index] ]; oneobject =[[hchy comesfromdict] valueforkey:[hchy key]]; [hchy setanobject:oneobject]; } else { hchy = [item copy] ; if ([[hchy anobject] iskindofclass:[nsdictionary class] ]) { // case: item comes dictionary. // ( if item expandable, outlineview ask item of index here. // dictionary or arrays expandable ) [hchy setkey:[[[hchy anobject] allkeys] objectatindex:index]]; oneobject =[[hchy anobject] valueforkey:[hchy key]]; [hchy setanobject:oneobject]; } else { if ([[hchy anobject] iskindofclass:[nsarray class] ]) { // case: item comes anarray // fetching array element [hchy setcomesfromdict:nil]; oneobject =[[hchy anobject] objectatindex:index]; [hchy setanobject:oneobject]; [hchy setkey:[nsstring stringwithformat:@"%ld",(long)index]]; }else { // case: item value // nslog(@"single kv pair : %@",[hchy key]); ; } } } if ( [[hchy anobject] iskindofclass:[nsarray class] ] || [[hchy anobject] iskindofclass:[nsdictionary class] ] ) { [hchy setvaluetext:@""]; [hchy setisheader:yes]; } else { [hchy setvaluetext:[hchy anobject]]; } return hchy; } - (id)outlineview:(nsoutlineview *)outlineview objectvaluefortablecolumn:(nstablecolumn *)tablecolumn byitem:(id)item { return item; }
Comments
Post a Comment