Skip to content

Commit

Permalink
Add array backing to illustrate deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderedge committed Mar 20, 2013
1 parent 6c0ab0b commit 04123be
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
74 changes: 73 additions & 1 deletion Examples/CollectionView-Simple/CollectionView/ViewController.m
Expand Up @@ -53,11 +53,45 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
NSString *kDetailedViewControllerID = @"DetailView"; // view controller storyboard id
NSString *kCellID = @"cellID"; // UICollectionViewCell storyboard id

@interface ViewController(){

NSMutableArray *_sections;

}
@end

@implementation ViewController

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

return [_sections count];

}

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
return 32;
return [_sections[section] count];
}

- (void)loadView{
[super loadView];

_sections = [NSMutableArray array];

for (NSUInteger i = 0; i < 3; i++) {

NSMutableArray *tempArray = [NSMutableArray arrayWithArray:@[[NSNull null],[NSNull null],[NSNull null]]];

[_sections addObject:tempArray];
}

}

- (void)viewDidLoad{
[super viewDidLoad];

self.collectionView.allowsMultipleSelection = YES;

}

- (PSUICollectionViewCell *)collectionView:(PSUICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
Expand Down Expand Up @@ -94,4 +128,42 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
}
}

- (IBAction)delete:(id)sender{

[self.collectionView performBatchUpdates:^{

[self.collectionView performBatchUpdates:^{

NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems];

NSArray *sortedArray = [indexPaths sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {

return [obj2 compare:obj1];

}];

[sortedArray enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {

[_sections[indexPath.section] removeObjectAtIndex:indexPath.item];

}];

[self.collectionView deleteItemsAtIndexPaths:indexPaths];



} completion:^(BOOL finished) {

[[self.collectionView indexPathsForSelectedItems] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

[self.collectionView deselectItemAtIndexPath:obj animated:NO];

}];

}];

} completion:nil];

}

@end
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2843" systemVersion="11G63" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="Pxb-db-V9M">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12C60" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="Pxb-db-V9M">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1929"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand Down Expand Up @@ -64,7 +64,13 @@
<outlet property="delegate" destination="dmE-Kn-TpH" id="pKl-zO-lPR"/>
</connections>
</collectionView>
<navigationItem key="navigationItem" title="Collection View" id="Qqd-gG-ZaX"/>
<navigationItem key="navigationItem" title="Collection View" id="Qqd-gG-ZaX">
<barButtonItem key="rightBarButtonItem" systemItem="trash" id="8uS-PN-C12">
<connections>
<action selector="delete:" destination="dmE-Kn-TpH" id="QWs-eh-jsA"/>
</connections>
</barButtonItem>
</navigationItem>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" barStyle="blackOpaque" prompted="NO"/>
</collectionViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="2FN-eK-xyQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -127,6 +133,9 @@
</class>
<class className="ViewController" superclassName="PSUICollectionViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ViewController.h"/>
<relationships>
<relationship kind="action" name="delete:"/>
</relationships>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
Expand Down

0 comments on commit 04123be

Please sign in to comment.