How to determine how many days / months / years have passed between two NSDate objects

Imagine you had two NSDate objects and you’d like to find out the time interval between those dates. NSDate objects alone won’t help us out there unless we do some serious NSDateFormatting and hair pulling. Lucky for us there are a few other classes available that will help us do this, namely NSCalendar and NSDateComponents. […]

How to avoid Spam User Registrations

In this podcast I will show you how to disable user registrations on your WordPress website. If you don’t have a legitimate reason to invite users to register themselves you’re leaving your site open to spammers who may from time to time try to “get in” (and we want to make sure we keep them … Read more

How to pop a UINavigationController in code

In UINavigationController speak, we “push” new controllers onto the stack (go forward), and we “pop” them off the stack (go back). The navigation controller handles all this for us. If you want to go back exactly one view controller, here’s how you can do it programmatically: // pop back to previous controller NSArray *myControllers = […]

How to change the back button text on a UINavigationController

In Your Storyboard I didn’t know the storyboard could do this, but it can: Select the Navigation Bar in question, then check the Attributes Inspector: In Code To set the title in code, you need to address the self.navigationItem.backBarButton property of your view controller and pass it a new UIBarButtonItem. Here’s one way of doing […]

How to “quick save” in Core Data

The easiest way to access a readily available save method is by importing AppDelegate into the class that wants to execute the save. Then we call a method in AppDelegate: AppDelegate *myAppDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; [myAppDelegate saveContext]; No reference to fetchedResultsController or managedObjectContext or any complex &error statements.

How to define a Protocol

Protocols are a great way to delegate responsibility from one class to another. Consider a view controller that brings up another view controller via a modal segue. Let’s call them ViewController and DetailViewController. When it comes to dismissing that DetailViewController, he could do it himself via [self dismissViewControllerAnimated:YES completion:nil]; However, the first ViewController wouldn’t be […]

How to dequeue UITableViewCells

Sometimes Xcode does a bit of magic behind the scenes which I don’t really understand. Consider this standard table view method to display cells: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”Cell”]; // populate your cell return cell; } Where do we actually ever create a UITableViewCell? All we’re asking here […]

How to hide (and show) the UISearchBar in a UITableView

If you add a UISearchBar to your table view (see previous article) it’s just sitting there by default. Chances are you’d like to hide it when your table view first loads. You can do this by adding the following code to your viewWillAppear method: – (void)viewWillAppear:(BOOL)animated { // scroll the search bar off-screen CGRect newBounds […]