Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>...By referring to <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/" rel="noreferrer">UICollectionView documentation</a></p> <blockquote> <p>You can accomplish: </p> <p>Inserting, Deleting, and Moving Sections and Items To insert, delete, or move a single section or item, follow these steps:</p> <ol> <li>Update the data in your data source object.</li> <li>Call the appropriate method of the collection view to insert or delete the section or item.</li> </ol> <p>It is critical that you update your data source before notifying the collection view of any changes. The collection view methods assume that your data source contains the currently correct data. If it does not, the collection view might receive the wrong set of items from your data source or ask for items that are not there and crash your app. When you add, delete, or move a single item programmatically, the collection view’s methods automatically create animations to reflect the changes. If you want to animate multiple changes together, though, you must perform all insert, delete, or move calls inside a block and pass that block to the performBatchUpdates:completion: method. The batch update process then animates all of your changes at the same time and you can freely mix calls to insert, delete, or move items within the same block.</p> </blockquote> <p>From your Question: you can for example register A gesture Recognizer, and Insert a NEW cell by doing the following: </p> <p>in </p> <pre><code>// in .h @property (nonatomic, strong) NSMutableArray *data; // in .m @synthesize data // - (void)ViewDidLoad{ //.... myCollectonView.dataSource = self; myCollectionView.delegate = self; data = [[NSMutableArray alloc] initWithObjects:@"0",@"1", @"2" @"3", @"4", @"5",@"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", nil]; UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(addNewCell:)]; swipeDown.direction = UISwipeGestureRecognizerDirectionDown; [self.view addGestureRecognizer:swipeDown]; //.. } -(void)addNewCell:(UISwipeGestureRecognizer *)downGesture { NSArray *newData = [[NSArray alloc] initWithObjects:@"otherData", nil]; [self.myCollectionView performBatchUpdates:^{ int resultsSize = [self.data count]; //data is the previous array of data [self.data addObjectsFromArray:newData]; NSMutableArray *arrayWithIndexPaths = [NSMutableArray array]; for (int i = resultsSize; i &lt; resultsSize + newData.count; i++) { [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]]; } [self.myCollectionView insertItemsAtIndexPaths:arrayWithIndexPaths]; } completion:nil]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload