5

Im inserting new section (insertSections) as well as new rows inside it (insertRowsAtIndexPaths). I'm using those two functions for the sake of withRowAnimation parameter.

With the help of stack community i've been able to override the in-built animation and make it longer - with the following trick in the cellForRowAtIndexPaths

    if(storedarraysofindexes[indexPath.section].containsIndex(indexPath.row)){
        //for _ in storedarraysofindexes[indexPath.section]{

        for _ in storedarraysofindexes[indexPath.section]{
            cell.alpha = 0

        UIView.animateWithDuration(4.0, animations:  {() in
            cell.alpha = 1.0
            }, completion:{(Bool)  in
            self.storedarraysofindexes[indexPath.section].removeIndex(indexPath.row)
        })}}

i'm saving every indexPath.row for every section into an array of NSMutableIndexSets and removing it after the effect was applied.

Animation works, but all of the cells are inserted at once. I want this animation to apply for every new inserted cell separately. Unfortunately, even for loop (mentioned in the code) didn't help me to solve this issue.

Any insights are greatly appreciated.

UPDATE

Added the code for insertRowsAtIndexPaths and insertSections wrapped in a function

func insertData(){

// step 1 - appending the array

my2darray.append(dataarray[option1]!)


// step 2 -generating a range of IndexPaths for the appended array values

     let insertedIndexPathRange = 0..<self.dataarray[self.option1]!.count + 1
     self.insertedIndexPaths = insertedIndexPathRange.map { NSIndexPath(forRow: $0, inSection: self.my2darray.count - 1) }



// step 3 - appending our NSMutableIndexSet with current indexes

     var update2 = NSMutableIndexSet ()

    for indexPathMe in insertedIndexPathRange{
        update2.addIndex(indexPathMe)
    }
    storedarraysofindexes += [update2]

// step 4 - inserting sections as well as rows

    self.tableView1.beginUpdates()
    self.tableView1.insertSections(NSIndexSet(index: self.my2darray.count - 1), withRowAnimation: .Fade)
    self.tableView1.insertRowsAtIndexPaths(insertedIndexPaths, withRowAnimation: .Fade)
    self.tableView1.endUpdates()
}
David Robertson
  • 1,561
  • 4
  • 19
  • 41

0 Answers0