UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift)

This bug is caused by having no tableView:estimatedHeightForRowAtIndexPath: method. It’s an optional part of the UITableViewDelegate protocol. This isn’t how it’s supposed to work. Apple’s documentation says: Providing an estimate the height of rows can improve the user experience when loading the table view. If the table contains variable height rows, it might be expensive … Read more

How do I adjust my popover to the size of the content in my tableview in swift?

In your UITableViewController’s viewDidLoad() you can add an observer: self.tableView.addObserver(self, forKeyPath: “contentSize”, options: .new, context: nil) Then add this method: override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { self.preferredContentSize = tableView.contentSize } Lastly, in viewDidDisappear(), make sure you remove the observer: tableView.removeObserver(self, forKeyPath: “contentSize”) This way the popover … Read more

UITableView separator line disappears when selecting cells in iOS7

I haven’t gotten to the bottom of it yet (at first glance it seems like an iOS 7 bug..), but I have found a workaround. In tableView:didSelectRowAtIndexPath, if you send both messages below, the issue is visually resolved (with the probable performance cost). [tableView deselectRowAtIndexPath:indexPath animated:YES]; [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; For this to work (for me), … Read more

UITableView in Swift

Also see matt’s answer which contains the second half of the solution Let’s find a solution without creating custom subclasses or nibs The real problem is in the fact that Swift distinguishes between objects that can be empty (nil) and objects that can’t be empty. If you don’t register a nib for your identifier, then … Read more

Is there a way to make UITableView cells in iOS 7 not have a line break in the separator?

For iOS7: if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; } For iOS8: First configure your table view as follows: if ([self.tableView respondsToSelector:@selector(layoutMargins)]) { self.tableView.layoutMargins = UIEdgeInsetsZero; } Then in your cellForRowAtIndexPath: method, configure the cell as follows: if ([cell respondsToSelector:@selector(layoutMargins)]) { cell.layoutMargins = UIEdgeInsetsZero; } Note: Include both layoutMargins and separatorInset, to support both iOS versions

Setting style of UITableViewCell when using iOS 6 UITableView dequeueReusableCellWithIdentifier:forIndexPath:

I know you said you didn’t want to create a subclass, but it looks inevitable. Based on the assembly code while testing in the iOS 6.0 simulator, UITableView creates new instances of UITableViewCell (or its subclasses) by performing [[<RegisteredClass> alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:<ReuseIdentifier>] In other words, the style sent (UITableViewCellStyleDefault) appears to be hard-coded. To get … Read more

UITableView is starting with an offset in iOS 7

The new iOS 7 implementation of UIViewController has a new set of options that allows the developer to choose if the system will automatically add insets for UIScrollView, UITableView and derivations. To disable this behaviour uncheck these boxes for all your wanted UIViewControllers in InterfaceBuilder, on UIViewController selected object inspector: For more details: Submit your … Read more

iOS 7 – How to display a date picker in place in a table view?

With iOS7, Apple released the sample code DateCell. Demonstrates formatted display of date objects in table cells and use of UIDatePicker to edit those values. As a delegate to this table, the sample uses the method “didSelectRowAtIndexPath” to open the UIDatePicker control. For iOS 6.x and earlier, UIViewAnimation is used for sliding the UIDatePicker up … Read more