Kodeco Forums

How To Make a Table View Drop-In Card Animation

A table view animations tutorial that shows you how to make a drop-in cards animation like in the Google+ app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2315-how-to-make-a-table-view-drop-in-card-animation

Hello,

Really nice animations and tutorial.

I’ve been running into an issue with scrolling speed though. It looks like the tableview scrolls REALLY slowly when the cells are animating in… when the cells aren’t animating the scrolling is fine. This happens in the sample project you linked once you increase the number of cells.

Here’s some code that reproduces the issue in your project.

  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return members.count * 100
  }

  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Card", forIndexPath: indexPath) as! CardTableViewCell
    let member = members[indexPath.row % members.count]
    cell.useMember(member)
    return cell
  }

Been banging my head on this for some time and no idea how to fix it.

Profiled the code, but it doesn’t seem to be a performance issue that’s causing the slow down.

I would like to ask you guys to update this tutorial. It’s relevant for a project I am working on since I want to use JSON and the members.swift is helpful in learning how to do that. However, I still want to be able to get it to run. I tried downloading the starter project and just building it, but it’s pretty old. I tried 2.3 swift and get these problems still. (I’m on XCode 8.1 with swift 3). I understand if you can’t or won’t but just making the request.

(I bought the iOS 10 by Tutorials book, and may see if there is something similar in there as well.
(Also bought the Unity book and am excited about jumping into that on my windows machine).

Hi there,
You can make the changes to the code to make it work in swift 2.3 Xcode 8.1. The NSData initializer and NSJSONSerialisation’s class method are marked “throws”. So we need to try those methods in a “do, catch” block.

Hi, i just updated in swift 3.

class func loadMembersFromFile(_ path:String) -> [Member]
  {
    var members:[Member] = []
    
    if let path = Bundle.main.path(forResource: "TeamMembers", ofType: "json") {
        do {
            let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
            let json = try JSONSerialization.jsonObject(with: data, options:.allowFragments) as! [String:AnyObject]
            let  team = json["team"]
            for field in team as? [AnyObject] ?? [] {
                let member = Member(dictionary: field as! NSDictionary)
                members.append(member)
            }
            
            
        } catch let error {
            print(error.localizedDescription)
        }
    } else {
        print("Invalid filename/path.")
    }
    return members
  }

Okay, I came back to this today as the cards intrigue me still, and seem to have it working in swift 3, but not with ajumal’s code. I’ve gotten a bit more experience since last post. I’d also add I changed the Build Settings for “Use Legacy Swift Language Version” to No, to force Swift 3 in the project.

Here are the relevant bits. There was one other function change that I accepted, forget the file, after using Edit, Convert, Convert to current swift syntax.

Here are the other bits (you’ll have to figure out that function when you choose the menu… sorry forgot to capture that it was not in Member.swift though.

Inside the init in Member.swift, swift 3 changes the function used to assign about:

   let unescapedAbout = dictionary["about"] as? String

about = unescapedAbout?.replacingOccurrences(of: "\\n", with:"\n")

Then shashank19909 basically had the other part that worked…

class func loadMembersFromFile(_ path:String) -> [Member]
  {
var members:[Member] = []

// var error:NSError? = nil
do {
    if let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
  let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? NSDictionary,
  let team = json["team"] as? [NSDictionary] {
    for memberDictionary in team {
      let member = Member(dictionary: memberDictionary)
      members.append(member)
    }
}
}
catch let error as NSError {
        print(error.description)
}
return members
  }

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]