Load a UIView from nib in Swift

My contribution: extension UIView { class func fromNib<T: UIView>() -> T { return Bundle(for: T.self).loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T } } Then call it like this: let myCustomView: CustomView = UIView.fromNib() ..or even: let myCustomView: CustomView = .fromNib()

Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?

I found a much better way that works independent of the nav controller. Right now, I have this working when embedded in a nav controller, and when NOT embedded (although I’m not using the nav controller right now, so there may be some bug I’ve not seen – e.g. the PUSH transition animation might go … Read more

How can I load storyboard programmatically from class?

In your storyboard go to the Attributes inspector and set the view controller’s Identifier. You can then present that view controller using the following code. UIStoryboard *sb = [UIStoryboard storyboardWithName:@”MainStoryboard” bundle:nil]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@”myViewController”]; vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentViewController:vc animated:YES completion:NULL];

How do you load custom UITableViewCells from Xib files?

The right solution is this: – (void)viewDidLoad { [super viewDidLoad]; UINib *nib = [UINib nibWithNibName:@”ItemCell” bundle:nil]; [[self tableView] registerNib:nib forCellReuseIdentifier:@”ItemCell”]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Create an instance of ItemCell PointsItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@”ItemCell”]; return cell; }

How to Empty Caches and Clean All Targets Xcode 4 and later

Command-Option-Shift-K to clean out the build folder. Even better, quit Xcode and clean out ~/Library/Developer/Xcode/DerivedData manually. Remove all its contents because there’s a bug where Xcode will run an old version of your project that’s in there somewhere. (Xcode 4.2 will show you the Derived Data folder: choose Window > Organizer and switch to the … Read more