Commits

José Manuel Sánchez Peñarroja committed 4db7d0b

Added methods to safely reload table rows and collection view items

Comments (0)

Files changed (6)

Example/Example.xcworkspace/xcshareddata/Example.xccheckout

 	<string>Example</string>
 	<key>IDESourceControlProjectOriginsDictionary</key>
 	<dict>
-		<key>317CA1BC-B8FD-4585-B89E-0CB3525D13C5</key>
+		<key>D175F9D2E8915D183808296EC98A2B82635D9065</key>
 		<string>ssh://bitbucket.org/buscarini/bmf.git</string>
 	</dict>
 	<key>IDESourceControlProjectPath</key>
 	<string>Example.xcworkspace</string>
 	<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
 	<dict>
-		<key>317CA1BC-B8FD-4585-B89E-0CB3525D13C5</key>
+		<key>D175F9D2E8915D183808296EC98A2B82635D9065</key>
 		<string>..</string>
 	</dict>
 	<key>IDESourceControlProjectURL</key>
 	<string>ssh://bitbucket.org/buscarini/bmf.git</string>
 	<key>IDESourceControlProjectVersion</key>
-	<integer>110</integer>
+	<integer>111</integer>
 	<key>IDESourceControlProjectWCCIdentifier</key>
-	<string>317CA1BC-B8FD-4585-B89E-0CB3525D13C5</string>
+	<string>D175F9D2E8915D183808296EC98A2B82635D9065</string>
 	<key>IDESourceControlProjectWCConfigurations</key>
 	<array>
 		<dict>
 			<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
 			<string>public.vcs.git</string>
 			<key>IDESourceControlWCCIdentifierKey</key>
-			<string>317CA1BC-B8FD-4585-B89E-0CB3525D13C5</string>
+			<string>D175F9D2E8915D183808296EC98A2B82635D9065</string>
 			<key>IDESourceControlWCCName</key>
 			<string>bmf</string>
 		</dict>

Example/Example.xcworkspace/xcuserdata/josanchez.xcuserdatad/UserInterfaceState.xcuserstate

Binary file modified.

bmf/ios/categories/UICollectionView+BMF.h

 
 - (BOOL) BMF_isEmpty;
 
+- (BOOL) BMF_indexPathValid:(NSIndexPath *) indexPath;
+
+- (void) BMF_reloadCellsAtIndexPaths:(NSArray *) indexPaths;
+
 @end

bmf/ios/categories/UICollectionView+BMF.m

 	return YES;
 }
 
+- (BOOL) BMF_indexPathValid:(NSIndexPath *) indexPath {
+	if (self.numberOfSections<=indexPath.section) return NO;
+	if ([self numberOfItemsInSection:indexPath.section]<=indexPath.row) return NO;
+	
+	return YES;
+}
+
+- (void) BMF_reloadCellsAtIndexPaths:(NSArray *) indexPaths {
+	BOOL reloadView = NO;
+	
+	for (NSIndexPath *indexPath in indexPaths) {
+		if (![self BMF_indexPathValid:indexPath]) {
+			reloadView = YES;
+			break;
+		}
+	}
+	
+	if (reloadView){
+		[self reloadData];
+	}
+	else {
+		[self reloadItemsAtIndexPaths:indexPaths];
+	}
+}
+
 @end

bmf/ios/categories/UITableView+BMF.h

 
 - (BOOL) BMF_isEmpty;
 
+- (BOOL) BMF_indexPathValid:(NSIndexPath *) indexPath;
+
+- (void) BMF_reloadCellsAtIndexPaths:(NSArray *) indexPaths withAnimation:(UITableViewRowAnimation) updateAnimation;
+
 @end

bmf/ios/categories/UITableView+BMF.m

 	return YES;
 }
 
+- (BOOL) BMF_indexPathValid:(NSIndexPath *) indexPath {
+	if (self.numberOfSections<=indexPath.section) return NO;
+	if ([self numberOfRowsInSection:indexPath.section]<=indexPath.row) return NO;
+	
+	return YES;
+}
+
+- (void) BMF_reloadCellsAtIndexPaths:(NSArray *) indexPaths withAnimation:(UITableViewRowAnimation) updateAnimation {
+	BOOL reloadView = NO;
+	
+	for (NSIndexPath *indexPath in indexPaths) {
+		if (![self BMF_indexPathValid:indexPath]) {
+			reloadView = YES;
+			break;
+		}
+	}
+	
+	if (reloadView){
+		[self reloadData];
+	}
+	else {
+		[self reloadRowsAtIndexPaths:indexPaths withRowAnimation:updateAnimation];
+	}
+}
+
 @end