Tapping the button doesn't change label


In the chapter we build two views app.
I did everything as suggested in the book, but tapping the button doesn’t change the label. Here is my code:

[code]#import <Foundation/Foundation.h>

@interface TimeViewController : UIViewController
IBOutlet UILabel *timeLabel;



[code]#import “TimeViewController.h”

@implementation TimeViewController

  • (IBAction)showCurrentTime:(id)sender
    NSDate *now = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    [timeLabel setText:[formatter stringFromDate:now]];



[code]#import “HypnoAppDelegate.h”
#import “HypnosisViewController.h”
#import “TimeViewController.h”

@implementation HypnoAppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //…creating an instance of our UIViewVontroller and setting it as a root view.
    HypnosisViewController *hvc = [[HypnosisViewController alloc] init];

    TimeViewController *tvc = [[TimeViewController alloc] init];
    [[self window] setRootViewController:tvc];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;

  • (void)applicationWillResignActive:(UIApplication *)application

  • (void)applicationDidEnterBackground:(UIApplication *)application

  • (void)applicationWillEnterForeground:(UIApplication *)application

  • (void)applicationDidBecomeActive:(UIApplication *)application

  • (void)applicationWillTerminate:(UIApplication *)application


I suspect my mistake is at the moment when we need to set connections in the xib file with file’s owner.
I control click on the file’s owner, choose “Received Actions: showCurrentTime” and drag it to the button. Then choose: “Did end on ending”.
I control click on the file’s owner, choose “Outlets: timeLabel” and drag it to the label.

Where is mistake?


I found my mistake while comparing this code with the provided with the book solutions. Mistake was made in the .xib file, when making connections with the file’s owner. Unfortunately in the book there is no information on how to properly do that. I don’t know how anyone can guess it.

The mistake was made in choosing wrong action for the button. Instead of choosing “Did end on ending” the option “Touch Up Inside” have to be chosen. That fixed the issue.