FIXED: A data view edited in a table view was duplicated after a reload.

Previously in CPTableTView, a view being edited was not cached when unloaded, for example when made invisible after scrolling or when calling -reloadData.
This situation was causing a duplicated view to be added at the same place when the data view was loaded again.
After this commit, edited data views are cached and resign their first responder status just before they are added to the queue because they can be reused at another place.

Test: Added a "reload data" button in ViewBasedCib example.
This commit is contained in:
cacaodev
2013-03-14 19:28:45 +01:00
parent 03b663463d
commit c8b812bbb5
4 changed files with 193 additions and 7 deletions
+4 -2
View File
@@ -3410,12 +3410,14 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
if (!dataViews || row >= dataViews.length)
continue;
if (row === _editingRow && column === _editingColumn)
[[self window] makeFirstResponder:self];
var dataView = [dataViews objectAtIndex:row];
[dataViews replaceObjectAtIndex:row withObject:nil];
if (row !== _editingRow || column !== _editingColumn)
[self _enqueueReusableDataView:dataView];
[self _enqueueReusableDataView:dataView];
}
}
}
@@ -21,6 +21,11 @@ CPLogRegister(CPLogConsole)
CPArray content @accessors;
}
- (IBAction)reload:(id)sender
{
[tableView reloadData];
}
- (void)applicationDidFinishLaunching:(CPNotification)note
{
content = [CPArray new];
File diff suppressed because one or more lines are too long
@@ -3,12 +3,12 @@
<data>
<int key="IBDocument.SystemTarget">1070</int>
<string key="IBDocument.SystemVersion">11G63</string>
<string key="IBDocument.InterfaceBuilderVersion">2844</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1138.51</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">2844</string>
<string key="NS.object.0">3084</string>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -405,11 +405,35 @@
<int key="NSPeriodicInterval">25</int>
</object>
</object>
<object class="NSButton" id="313440180">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">265</int>
<string key="NSFrame">{{712, 314}, {116, 32}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="571760103"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="733408462">
<int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents">Reload Data</string>
<reference key="NSSupport" ref="1069422166"/>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="313440180"/>
<int key="NSButtonFlags">-2038284288</int>
<int key="NSButtonFlags2">129</int>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">200</int>
<int key="NSPeriodicInterval">25</int>
</object>
</object>
</object>
<string key="NSFrameSize">{994, 356}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="571760103"/>
<reference key="NSNextKeyView" ref="313440180"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
@@ -458,6 +482,14 @@
</object>
<int key="connectionID">596</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">reload:</string>
<reference key="source" ref="635946545"/>
<reference key="destination" ref="313440180"/>
</object>
<int key="connectionID">723</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">content: arrangedObjects</string>
@@ -1191,6 +1223,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="62651824"/>
<reference ref="571760103"/>
<reference ref="313440180"/>
</object>
<reference key="parent" ref="972006081"/>
</object>
@@ -1537,6 +1570,20 @@
<reference key="object" ref="491917911"/>
<reference key="parent" ref="153746192"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">720</int>
<reference key="object" ref="313440180"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="733408462"/>
</object>
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">721</int>
<reference key="object" ref="733408462"/>
<reference key="parent" ref="313440180"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -1608,6 +1655,8 @@
<string>711.IBPluginDependency</string>
<string>716.IBPluginDependency</string>
<string>717.IBPluginDependency</string>
<string>720.IBPluginDependency</string>
<string>721.IBPluginDependency</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1687,6 +1736,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -1701,7 +1752,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">719</int>
<int key="maxID">723</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1709,6 +1760,28 @@
<object class="IBPartialClassDescription">
<string key="className">AppController</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">reload:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">reload:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">reload:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">tableView</string>
<string key="NS.object.0">NSTableView</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">tableView</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">tableView</string>
<string key="candidateClassName">NSTableView</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/AppController.h</string>
@@ -1717,6 +1790,112 @@
<object class="IBPartialClassDescription">
<string key="className">TableViewDelegate</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>_sliderAction:</string>
<string>_textFieldBezeledAction:</string>
<string>_textFieldNotBezeledAction:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>_sliderAction:</string>
<string>_textFieldBezeledAction:</string>
<string>_textFieldNotBezeledAction:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBActionInfo">
<string key="name">_sliderAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">_textFieldBezeledAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">_textFieldNotBezeledAction:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>contentController</string>
<string>externalView</string>
<string>imageView</string>
<string>personView</string>
<string>placeView</string>
<string>textField</string>
<string>view</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSArrayController</string>
<string>NSView</string>
<string>NSImageView</string>
<string>NSView</string>
<string>NSView</string>
<string>NSTextField</string>
<string>CPTableCellView</string>
</object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>contentController</string>
<string>externalView</string>
<string>imageView</string>
<string>personView</string>
<string>placeView</string>
<string>textField</string>
<string>view</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">contentController</string>
<string key="candidateClassName">NSArrayController</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">externalView</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">imageView</string>
<string key="candidateClassName">NSImageView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">personView</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">placeView</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">textField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">view</string>
<string key="candidateClassName">CPTableCellView</string>
</object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/TableViewDelegate.h</string>