UITableView with two custom cells (multiple identifiers)

* I’ve renamed some of your NIB/Class names for a better understanding. * First, you should register each cells’ NIB: – (void)viewDidLoad{ [super viewDidLoad]; static NSString *CellIdentifier1 = @”ContentCell”; static NSString *CellIdentifier2 = @”SpaceCell”; UINib *nib = [UINib nibWithNibName:@”CellViewNIBName” bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier1]; nib = [UINib nibWithNibName:@”CellSpaceNIBName” bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier2]; self.contentView.hidden = YES; [self … Read more

table header view height is wrong when using auto layout, IB, and font sizes

Note: A Swift 3+ version can be found here: https://gist.github.com/marcoarment/1105553afba6b4900c10#gistcomment-1933639 The idea is to calculate header’s height with help of systemLayoutSizeFittingSize:targetSize. Returns the size of the view that satisfies the constraints it holds. Determines the best size of the view considering all constraints it holds and those of its subviews. After changing header’s height it … Read more

Iphone – when to calculate heightForRowAtIndexPath for a tableview when each cell height is dynamic?

The way Apple implements UITableView is not intuitive to everyone and it’s easy to misunderstand the role of heightForRowAtIndexPath:. The general intention is that this is a faster and light-on-memory method that can be called for every row in the table quite frequently. This contrasts with cellForRowAtIndexPath: which is often slower and more memory intensive, … Read more

iOS – Delayed “Touch Down” event for UIButton in UITableViewCell

This is caused by the UIScrollView property delaysContentTouches. It used to be sufficient to just set that property to NO for the UITableView itself, but that will only work for subviews of the table that are not encased in another UIScrollView. UITableViewCells contain an internal scroll view in iOS 7 so you will need to … Read more

How to implement UISearchController in UITableView – Swift

Yes, the way search works has been radically changed for what I consider to be a better system. The new system is much better and straight to the point for most simple implementations. Using it is pretty straightforward. First, make your class comply with the UISearchResultsUpdating protocol. class MyTableViewController: UITableViewController, UISearchResultsUpdating {} Add it the … Read more

When should translatesAutoresizingMaskIntoConstraints be set to true?

translatesAutoresizingMaskIntoConstraints needs to be set to false when: You Create a UIView-based object in code (Storyboard/NIB will set it for you if the file has autolayout enabled), And you want to use auto layout for this view rather than frame-based layout, And the view will be added to a view hierarchy that is using auto … Read more

UITableViewCell: rounded corners and shadow

This question comes at a good time! I literally JUST solved this same issue myself. Create a UIView (let’s refer to it as mainBackground) inside your cell’s Content View. This will contain all of your cell’s content. Position it and apply necessary constraints in the Storyboard. Create another UIView. This one will be the one … Read more