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.
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!