1

TL;TR: Navigation bar from navigation controller causes lag when scrolling UItableView. When hidden, no lag at all.

I've been struggling some days with my UITableViews being laggy. After some stackoverflow browsing I've found pretty much nothing that could cause my UItableViews to lag. Some things I checked:

  • I make use of ReusableIdentifier
  • I have my class as a custom class, Outlets are in that custom class, and just setting those outlets on tableView cellForRowAtIndexPath
  • My cells do contain images, but they are images from my assets, so, according to this answer this should not cause any trouble as it caches these images already for me.

Now today, I was creating another View Controller, for testing I set the Is Initial View Controller to that view. When done I set the Is Initial View Controller to the first view controller instead of the Navigation controller. I was happy because it didn't gave me any lag on scrolling when opening the new view. Then I noticed I was missing my navigation button, put the Is Initial View Controller back to the navigation controller and guess what, my UITableView lags like hell!

Now I'm really wondering what causes this lag.

I use this piece of code on some views to hide and show the bar:

override func viewWillAppear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
    super.viewWillDisappear(animated)
}

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
    super.viewWillDisappear(animated)
}

I noticed, that when the navigation bar is shown, it gives lag. When it is hidden, it does not. Now the navigation controller bar is just standard, nothing fancy (yet)

I don't have that much knowledge of Instruments, but if it helps for you:

With navigation bar enabled: image

Without navigation bar enabled: image

Structure

This is how two of my views look like, both having a tableView, both having the same issue with the Navigation Bar, one containing only an image, label and button. The other one containing some more stuff, but the difference is almost the same, lagging when navigation bar is not hidden.

structure

Segue

There are different methods of showing another view, but so far it does not make any difference. Having a Segue from the button directly to the view gives the same lag then when using self.navigationController?.pushViewController(...)

Iphone 6 Plus

On the Iphone 6 Plus, even without navigation bar, this phone makes it even more laggy. However this could be because of the old MacBook I'm using. Scaling down to 33% and it lags when showing the top and bottom menu from iphone itself, so I guess that is just a issue of my own.

Additional code:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell: ItemCell = self.LicenseTableView.dequeueReusableCellWithIdentifier("itemCell", forIndexPath: indexPath) as! ItemCell!
    cell.lblItemDescription?.text = self.ItemsList[indexPath.row].description
    return cell    
}

Thanks for reading, hope you can help, if you need any additional information, let me know!

Community
  • 1
  • 1
CularBytes
  • 9,924
  • 8
  • 76
  • 101
  • Well, making a new cell for displaying content is a memory-expensive operation, especially when you have a lot dynamic content to be displayed. So be sure you make use of `dequeueReusableCellWithIdentifier:forIndexPath` to avoid filling up memory and slowing your app. – Dree Jul 15 '15 at 13:32
  • @Dree I've updated my question, this is how simple I do make use of `dequeueReusableCellWithIdentifier:forIndexPath`. – CularBytes Jul 15 '15 at 13:45
  • I found an article that summarizes all the possibile issues that may cause table containing images scrolling to be slow and lists some solution. Hope this helps: http://iosinjordan.tumblr.com/post/56778173518/help-my-tables-dont-scroll-smoothly – Dree Jul 15 '15 at 13:58

1 Answers1

1

Try the following: Open the NavigationController scene in the storyboard. Select the navigationBar and disable the translucency:

enter image description here

In addition: Table views have a lot performance problems when the content has transparency. To find the problematic subviews, select in the Simulator "Debug > Color Blended Layers". All the red views are problematic. Try to remove transparency from those views.

dasdom
  • 13,975
  • 2
  • 47
  • 58
  • Well, that reduces it a little bit. Still a noticeable difference between with or without navigation bar, and of course it doesn't look very nice but acceptable... Thanks for that tip on the Color Blending Layers. the views INSIDE the cells seem to be fine, all green expect for the images. Now the Cell and table view itself do have set clear color for the background because of the beautiful background image. I want to keep it that way since that is how we planned our design (and it works perfectly on android). Do you have any suggestions for performance increase with transparent background? – CularBytes Jul 15 '15 at 15:15