kent@theappcodellc.com

August 28, 2015

TheAppCodeBlog is no longer active. When I first started it App Code, the IDE, had not come out yet. Now in an effort to avoid any confusion with being associated with App Code I am letting this site go, I don’t know how much longer it wil be accessible.

Please come visit my new site at http://www.kefbytes.com

iOS Programming Tutorial – Protocol Delegate method of passing data

Passing data using the protocol delegate pattern.

“Objective-C allows you to define protocols, which declare the methods expected to be used for a particular situation.”

“A protocol, by contrast, is used to declare methods and properties that are independent of any specific class.”

“A delegate is an object that acts on behalf of, or in coordination with, another object when that object encounters an event in a program.”
Continue reading

iOS Programming Tutorial – Core Data Using A NSFetchedResultsController

Today we’re going to expand on the first Core Data tutorial in this series http://www.theappcodeblog.com/?p=249. We’ll be changing the table view to use an NSFetchedController which really makes keeping track of changes in our data and handles the updating of our view for us.

If you want to grab the code from part one which we’ll be starting with go here.
http://www.theappcodeblog.com/code/_CoreDataTest.zip

1.) To start off we’re going to strip out all the parts of the code that we won’t need now that we’ll be using the fetched results controller.

Open up PeopleTableViewController.m

Remove the properties for the array’s and the fetch request. Here’s what our private interface portion looks like now.

@interface PeopleTableViewController ()
@property (nonatomic, strong) Person *person;
@end

Next remove the fetchTheData method and all references to it.

Also remove the viewWillAppear method.

Then remove any commented out methods.

I’m also going to remove the didReceiveMemoryWarning method, we won’t need it for this demo.
Continue reading

iOS Programming Tutorial – Local Notifications with iOS 8

Today we’re going to take a look at creating Local Notifications in iOS 8. The process of creating notifications changed with iOS 8. We now need to ask the user for permission to display notifications and register the settings.

This will be a short tutorial, and I won’t waste your time detailing how to set up an app step by step.

1.) Start by creating a single view app named NotifDemo and with a UI that looks something like this.

Description of pic
Continue reading

iOS Programming Tutorial – UIScrollView

Implementing a UIScrollView is a very simple thing to do. It’s really just a matter of adding the scroll view to your existing view and then adding a dew methods to the controller.

This will be one of the shorter and easier tutorials we do. Because our focus in on the scroll view itself, I’m not going to take time to explain what we’re doing when we’re setting up our app.

1.) The first thing we need to do is set up a very simple application to work with. Create a single view application and name it ScrollViewDemo.

We’ll do all of our work in the single view and controller that Xcode create for us. Before we add the scroll view let’s just display an image in the view. Open up ViewController.m add add these properties.

#import "ViewController.h"
 
@interface ViewController ()
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) NSURL *imageURL;
@end

Continue reading

iOS Programming Tutorial – Core Data Part 1: Passing Around NSManagedObjectContext

I originally started doing iOS development sometime back in 2010, before my 3 year exile into .net. This was a time before Storyboards and as a developer you found yourself doing a lot of work in the didFinishLaunchingWithOptions method. In fact you could set up all your controllers there. You’d create a Tab Bar controller and hook it up with a Navigation Controller and then add all kinds of view controllers to it, all right there in the app delegate. While this added a lot of code that is not necessary these days using Storyboard, it did make it a pretty easy thing to pass the managedObjectContext for your Core Data into each of the controllers.

When I finally came back to iOS, after my time spent in the wilderness of C#, I had to learn all about storyboards and what they did to change the way I had previously developed my apps. Beyond just saving a lot of UI code from being written, one of the first things I discovered was my old methods of using Core Data were a bit stale. Thus my adventure in learning the new methods for Core Data and even more so passing around a managedObjectContext.

Description of pic
Continue reading

iOS Programming Tutorial – Storyboard Tutorial

This tutorial will be an introduction to using Storyboards in Xcode. Storyboards were introduced with the release of Xcode 4.2 and simplified the process of creating UI for apps. Prior to the introduction of Storyboards developers had to create a new nib file for each view and associate it with a view controller managing how all those views related to each other. Storyboards changed all of that and allowed the developer to spend more time focusing on the logic of the app and less time coding for the UI.

If you have used Storyboards you will not find anything new here. But if you are just starting out follow along and see how easy storyboards make our life.

Let’s get started.

1.) Open up Xcode and create a new Tabbed Application project named StoryboardTest.

Description of pic


Continue reading

iPhone app development tutorial – add an intro view to your tab bar app

This tutorial was originally published in April 2011

This tutorial is on adding an intro view to your app. In this instance we’ll be adding it to a tab bar app. This is not the use of a splash view. A splash view is one which is shown each time an app loads and is only shown for a few short second, going away without any user interaction. Our intro view will be one that is shown at a specific time, mostly when the app is loaded for the first time. The view will state visible until the user takes some action to dismiss the view. We will be showing our view modally and using a boolean to determine whether to show the view when the app is loaded. In addition we will be storing the boolean in a plist and loading it’s value to determine whether to show our intro view.

So now that we’ve laid out what we want to do, let’s get started.

Simulator Shot
Continue reading

iPhone App Development – Add a twitter button in your app

This tutorial was originally published in March 2011

This tutorial is going to be about adding a Twitter button to your app. By doing this you allow a user to tweet straight from your app rather than exiting and using another app. This became available in iOS 5, and it really is easy to do. Our app here is going to be very simple, but the steps to do this can be used in any app.

App Screen Shot

1.) Let’s start by creating a single view app.

Create a Single View Appt

Go ahead and name the app TwitterTutorial, we’ll use Automatic Reference Counting but will not be using a Storyboard.

Name the App

2.) Before we do anything else let’s import the twitter framework. If you are unclear about how to do this you can check this tutorial.


Add a framework in Xcode 4 Tutorial

Add the Twitter Framework

Frameworks

3.) Our view is going to be very simple. I’m going to spice it up just a little by changing the background and adding an image, but the main thing is to just add the button.

Our view

3.) Open up the view controller header file and declare an IBAction.

- (IBAction)tweetAway;

That’s all we have to do in the header file.

4.) Now open up the view controller implementation file and import Twitter.h.

#import "ViewController.h"
#import "Twitter/Twitter.h"

5.) Next create implement the IBAction that we declared in the header file

- (IBAction)tweetAway 
{
 
    //This creates the tweet view that we'll present modally when a user clicks the button.
    TWTweetComposeViewController *tweetView = [[TWTweetComposeViewController alloc] init];
 
    //You set a default tweet to show in the view
    [tweetView setInitialText:@"Here's a tweet from your app"];
 
    //You can tweet an image
    [tweetView addImage:[UIImage imageNamed:@"twitter-logo.png"]];
 
    //You can also add a link to the tweet
    [tweetView addURL:[NSURL URLWithString:@"http://www.theappcodeblog.com"]];
 
    // Specify a block to be called when the user is finished. This block is not guaranteed
    // to be called on any particular thread.
    // All we are doing is dismissing the modal view when the tweet is sent.
    tweetView.completionHandler = ^(TWTweetComposeViewControllerResult result)
    {
        [self dismissModalViewControllerAnimated:YES];
    };
 
    //present tweet view modally
    [self presentModalViewController:tweetView animated:YES];
}

6.) Last thing is to hook up the IBAction to our button.

Link IBAction

7.) And finally run the app.

App Screen Shot

Click the Tweet button and the Tweet view will open modally.

App Screen Shot 2


That’s it, here’s the code.