Skip to content
Browse files

Add array backing to illustrate deletion

  • Loading branch information...
1 parent 6c0ab0b commit 04123be45bc7891e1cf81b19faf9e7d9b2537940 @alexanderedge alexanderedge committed Mar 14, 2013
View
74 Examples/CollectionView-Simple/CollectionView/ViewController.m
@@ -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;
@@ -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
View
15 Examples/CollectionView-Simple/CollectionView/en.lproj/MainStoryboard.storyboard
@@ -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-->
@@ -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"/>
@@ -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">

0 comments on commit 04123be

Please sign in to comment.
Something went wrong with that request. Please try again.