Reputation: 709
I'm not sure if this is something to do with SWIFT or some bug, but i used to be able to call this in objective c to enlarge and shrink tableview cells:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if([indexPath isEqual:[tableView indexPathForSelectedRow]]) {
return 500.0;
}
return 81.0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (isShowingDetails == YES) {
isShowDetails = NO;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView beginUpdates];
[tableView endUpdates];
}else {
isShowingDetails = YES;
[tableView beginUpdates];
[tableView endUpdates];
}
}
But now if i try and do it using this SWIFT Version, when deselecting the row, it has a really bad delay of a couple of seconds.. heres the SWIFT version:
override func tableView(tableView: UITableView!,
heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
if(indexPath.isEqual(tableView.indexPathForSelectedRow())) {
return 500.0;
}
return 81.0;
}
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
if(isExpanded == true)
{
isExpanded = false
self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
self.tableView.beginUpdates()
self.tableView.endUpdates()
} else {
isExpanded = true
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
}
Any ideas at all? as i said i'm not sure if its the way i wrote it, but i don't see why i never had any issues with it in objective C. It works fine in SWIFT when selecting it the first time, just that delay of updating is really a pain..
Upvotes: 3
Views: 4197
Reputation: 80
I have the same problem. After updating to ios 8. My tableview became slow. I have a tabbar based app. App has 2 tabs both contains tableview. Tableview controller on first tab has around 350 cells and second one contains around 40. So when i switch from tab2 to tab1, i get a huge delay of 2 seconds. But when i switch from tab1 to tab2, then it is faster because tableview on tab2 has less cells comparatively. But my problem is that, when i run the same code same app in any ios6 or ios7 device. It is faster, even there is no trackable delay. And didselect is slow as well in ios 8, the tableview makes the whole viewcontroller super slow. I tap everywhere and i get delay. App works super smooth on ios7 though.
Upvotes: 0
Reputation: 31304
Table views in iOS 8 can now have their cells declare their own heights, rather than needing to implement them in the delegate methods. You may want to look at doing that instead, if you're able to, because it will be a cleaner way of doing what you're trying to do here.
Otherwise, have you benchmarked your Objective-C code in iOS 8 to ensure the performance hit isn't in the UIKit framework itself? Swift is still calling the underlying frameworks, and that's where the bulk of the work is happening. If both Objective-C and Swift implementations seem equally slow on iOS 8 you know it's a problem with the UITableView methods themselves, and you can file a bug against them. And if it's only Swift, you know it's a bug with Swift / the UIKit/Objective-C bridging, and can file a bug against that.
Upvotes: 1