View Single Post
Old November 22nd, 2013, 12:45 PM
thepianoguy thepianoguy is offline
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts

These are the steps you will need to take.
1. In the Project Navigator (interface column on the left) delete the storyboard and the ViewController.h and .m files. (select Move to trash in the dialogue that comes up when you hit the delete key)
2. In the Main Menu select New>File. In the dialogue that comes up name the file ViewController, and choose subclass of UIViewController. Make sure the "With XIB for user interface" box is checked
3. In the Project Navigator select the uppermost item (has Xcode icon and the project name) In the Main editor you should see an option for "General". Under this there is a disclosure triangle and a section titled Deployment Info. If it is not open, open the disclosure to see your options. Delete the word "Main" from the Main Interface textfield.
4. Select the AppDelegate.h file edit it to read as follows (changes are in bold):
#import <UIKit/UIKit.h>
@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;

5. Select the AppDelegate.m file and edit it to read as follows (changes are in bold):
#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
You can now follow the steps in the book to set up the interface. There are 2 errors in the book on p. 40 that will need to be corrected as well. Steps 18 and 19 need to refer to mySlider as self.mySlider

- (IBAction)buttonPressed:(id)sender {
    self.myLabel.text = [[NSNumber numberWithInt:counter] stringValue];
    self.mySlider.value = counter;

- (IBAction)sliderMoved:(id)sender {
    counter = self.mySlider.value;
    self.myLabel.text = [[NSNumber numberWithInt:counter] stringValue];
In the downloadable code the author did not initially make the slider outlet a property, so it can be accessed directly. As it is in the book it is a property, so the accessor should be used. The implementation in the book did not reflect this change.