I have a ViewController
in my UITabBarController
that takes a gnawing 5-8 seconds to load.
No heavy processing, no significant callback chains and no network calls.
I asked this question earlier:
ViewController transition bottleneck in UITabBarController
And I think I have pinpointed the source of the problem, so I will go into more detail here.
I have a UITableView
whose dataSource changes based on the value of a UISegmentedControl
. I am displaying friend requests, and the segmented control manages the display of Outgoing
and Incoming
ones.
override func viewDidLoad() {
super.viewDidLoad()
friendRequestsToDisplay = FriendRequestManager.instance.incomingFriendRequests
tableView.delegate = self
tableView.dataSource = self
self.refreshControl = UIRefreshControl()
self.refreshControl.addTarget(self, action: "refreshRequests:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refreshControl)
incomingFriendRequests = FriendRequestManager.instance.incomingFriendRequests
outgoingFriendRequests = FriendRequestManager.instance.outgoingFriendRequests
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return friendRequestsToDisplay.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let bookRequest = self.friendRequestsToDisplay[indexPath.row]
if let cell = tableView.dequeueReusableCellWithIdentifier("RequestCell", forIndexPath: indexPath) as? RequestCell {
cell.configureCell(friendRequest, isAnIncomingRequest: isAnIncomingRequest)
return cell
} else {
return UITableViewCell()
}
}
According to breakpoints and for some odd reason, numberOfSectionsInTableView
and numberOfRowsInSection
gets called exactly twice the number of total friendRequests
loaded
And dequeueReusableCellWithIdentifier
takes about 4 seconds to load with a breakpoint.
Here are the results from the Time Profile in Instruments:
Anybody have an idea as to what could be the source of the lag?