Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rubu

macrumors newbie
Original poster
Jun 4, 2014
4
0
Hey guys,
im new to xcode and all i wanted to do was a simple countdown from 10 to 0 activated by a button and displayed on a label.
This is my Viewcontroller.h
Code:
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
     IBOutlet UILabel *timerLabel;
    IBOutlet UILabel *scoreLabel;
    
    
    NSTimer *timer;
    NSInteger seconds;
    NSInteger count;
    
}


-(IBAction)setupTimer;
-(IBAction)startGame;



@end

And this the ViewController.m file:

Code:
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)startGame {
    count = 0;
    
    scoreLabel.text = [NSString stringWithFormat:@"Score: %li", (long)count];

}


-(void)startTimer {
    seconds = 10;
    
    timerLabel.text = [NSString stringWithFormat:@"Time: %li", (long)seconds];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
             target:self
                            selector:@selector(substractTime)
                                           userInfo:nil repeats:YES];
    
}



-(void)substractTime {
    seconds--;
    timerLabel.text = [NSString stringWithFormat:@"Time: %li", (long)seconds];
    
}


-(IBAction)setupTimer {
    [self startTimer];
}




@end

if i run the app it says: Thread 1: breakpoint 1.1 and stops the app.

i don't know what it means nor do i know why its an error in the main.m
here it is:

Code:
#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
    [U]    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));[/U]
    }
}
the underlined text shows where the breakpoint is marked.

please help me. its such a basic app and i don't understand why it won't work...

EDIT: Heres the Debug Log from the Console:
Code:
2014-06-04 20:29:39.612 Countdown3[9696:60b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x109368b70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key timeLabel.'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000101947495 __exceptionPreprocess + 165
	1   libobjc.A.dylib                     0x00000001016a699e objc_exception_throw + 43
	2   CoreFoundation                      0x00000001019cb919 -[NSException raise] + 9
	3   Foundation                          0x0000000101287530 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
	4   CoreFoundation                      0x0000000101943400 -[NSArray makeObjectsPerformSelector:] + 224
	5   UIKit                               0x00000001004ae8a6 -[UINib instantiateWithOwner:options:] + 1131
	6   UIKit                               0x0000000100348b0c -[UIViewController _loadViewFromNibNamed:bundle:] + 245
	7   UIKit                               0x0000000100349149 -[UIViewController loadView] + 112
	8   UIKit                               0x00000001003493b7 -[UIViewController loadViewIfRequired] + 75
	9   UIKit                               0x0000000100349777 -[UIViewController view] + 29
	10  UIKit                               0x000000010028996b -[UIWindow addRootViewControllerViewIfPossible] + 58
	11  UIKit                               0x0000000100289c70 -[UIWindow _setHidden:forced:] + 282
	12  UIKit                               0x0000000100292ffa -[UIWindow makeKeyAndVisible] + 51
	13  UIKit                               0x000000010024ec98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
	14  UIKit                               0x0000000100252a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
	15  UIKit                               0x0000000100263d4c -[UIApplication handleEvent:withNewEvent:] + 3189
	16  UIKit                               0x0000000100264216 -[UIApplication sendEvent:] + 79
	17  UIKit                               0x0000000100254086 _UIApplicationHandleEvent + 578
	18  GraphicsServices                    0x0000000103ac071a _PurpleEventCallback + 762
	19  GraphicsServices                    0x0000000103ac01e1 PurpleEventCallback + 35
	20  CoreFoundation                      0x00000001018c9679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
	21  CoreFoundation                      0x00000001018c944e __CFRunLoopDoSource1 + 478
	22  CoreFoundation                      0x00000001018f2903 __CFRunLoopRun + 1939
	23  CoreFoundation                      0x00000001018f1d83 CFRunLoopRunSpecific + 467
	24  UIKit                               0x00000001002522e1 -[UIApplication _run] + 609
	25  UIKit                               0x0000000100253e33 UIApplicationMain + 1010
	26  Countdown3                          0x0000000100001f83 main + 115
	27  libdyld.dylib                       0x0000000101fdf5fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
 
Last edited:
i have done so but it just won't work..
always the same error message...

please help me
 
NEW problem.... Black screen

Ok this is what i did:
-fixed the main.storyboard file.
- inserted this (underlined lines) in the Appdelegate.m:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [U]self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    UIViewController *viewController = [[UIViewController alloc] init];
    [self.window setRootViewController:viewController];
    
    [self.window makeKeyAndVisible];[/U]
    // Override point for customization after application launch.
    return YES;
}

The good news: I do not get any more error messages
Bad news: Its just black. after launching the app nothing happens and it stays black.

i don't know what to do anymore...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.