Jan 04 2009
By
Jourdein | Filled under:
Code,
Dev
I was scratching my head of why the heck does the my tableview does not automatically update its data.
My binding:
NSArrayController = ACIssues
Controller Class = Issue Controller (have NSArray property subviewControllers)
ACIssues has it contentArray binded to subviewControllers’s array in Issue Controller. Somehow, changes made to the array of subviewControllers in Issue Controller does not reflect on other table which I had it binded to ACIssues.
After searching the internet, I found this
http://boredzo.org/blog/archives/2008-11-26/how-to-work-with-a-bound-to-array (open in new window)
Very good one. What it said… There’re right and wrong way to bind.
The right way is by using indexed accessors. Then, your Array Controller will see any changes you’ve made. What I did was creating indexed accessor methods.
- (void)insertObject:(id)object inSubviewControllersAtIndex:(unsigned)index {
[[self subviewControllers] insertObject:object atIndex:index];
}
- (void)removeObjectFromSubviewControllersAtIndex:(unsigned)index {
[[self subviewControllers] removeObjectAtIndex: index];
}
and calling it where I wanted to change the array.
[self insertObject:obj inSubviewControllersAtIndex:(index + 1)];
[self removeObjectFromSubviewControllersAtIndex:index];
the structure of this indexed accessor:
insertObject:(id)object inKeyAtIndex:(unsigned)index
where key is the property or in my case array that is binded to the Array Controller.