How to pass an Index Path to another table

Say you have a central array somewhere and would like display this in more detail via two table view controllers. Instead of passing only the relevant information, you want to pass the entire index path from table1 to table2 and beyond. You can pass data in the prepareForSegue:sender method and let the Storyboard to the […]

How to create a custom button

We can do this by setting properties of the UIButton for the states “normal” and “highlighted”. First we create pointers to the images, then we tell the button to use said images for each state: If the button has transparency enabled use the “custom” setting in your Storyboard. If the button should have a dynamic […]

How to add the “spinning wheel” Activity Indicator to a web view

It’s always good to have something happening while you’re loading a UIWebView. You can use the UIActivityIndicator for this. It’s basically an animated GIF file that you can connect to your code like many other elements. To make it work we need to conform to the UIWebViewDelegate protocol and then query our web view to […]

How to convert an NSArray into an NSMutableArray

There’s a handy function called arrayWithArray that we can use: NSMutableArray *myNewArray = [[NSMutableArray alloc]init]; myNewArray = [NSMutableArray arrayWithArray:myOldArray]; Likewise we can convert a mutable array into a standard one: NSArray *myStandardArray = [[NSArray alloc]init]; myStandardArray = [NSArray arrayWithArray:myMutableArray];

How to change the text on a Button

You can set the title of a button depending on its control state. An unselected untoched button has a UIControlStateNormal, but Xcode will show you all the other options you have at your fingertips. To access this property you need to create an IBOutlet on the button. If you also want the button to trigger […]

How to convert an integer into a string (text object)

I keep forgetting how to do this so here it is: if you have an integer and you want to print it out, say in a UILabel you can use the initWithFormat method of NSString like so: NSString *myNumber; myNumber = [[NSString alloc] initWithFormat:@”%d”, myInteger]; self.myLabel.text = myNumber; The secret here is the @”%d” which […]

How to share data between Navigation Controllers

The Root Navigation Controller can serve as a data model. Each View Controller connected to the Navigation Controller via push segue can access its properties like so: ((MyNavController *)self.parentViewController).mySourceProperty Here’s an example. MyNavController is the class for the Navigation Controller. This snipped is called from any View Controller in sequence and assumes we have an […]

How to trigger a Modal Segue

Once you’ve connected two View Controllers via a Segue in the storyboard you need to give it an identifier so we can call it in code like so: [self performSegueWithIdentifier:@”showDetail” sender:self]; Dismiss it via an action like this: [self dismissViewControllerAnimated:YES completion:nil];