Simple issue with basic iPhone application.

I have a simple app that I am trying to get functioning properly. The app will launch and run in the simulator and quit before I can see anything. I have made my Label Connection between the File Owner and the label by selecting the label on my background, selecting Connections Inspector in the Tools menu and then dragging from the plus sign under 'New Referencing Outlet' to the 'File Owner'. Once done I selected my label and this is the result. any idea how to fix this so the app will run now?

iPhone, iPhone OS 3.1.2

Posted on Jan 28, 2010 1:01 PM

Reply
19 replies

Jan 28, 2010 3:30 PM in response to K T

I thought I did that. When I first create the app I put a label on a screen, then I set its attributes, write the class files, merge them and save. When I go in xCode and build+run I see the label in the iPhone simulator as expected. When I go back into xCode to add my code to manipulate the UI is when I get this error.

I need some help. How do you fix this error please?

Jan 28, 2010 3:43 PM in response to K T

This is all the code.... I was following the tutorial found here: http://appsamuck.com/day1.html

Thanks, I'm a newbie top the Mac world.

// MinutesToMidnightViewController.m
// MinutesToMidnight

#import "MinutesToMidnightViewController.h"

@implementation MinutesToMidnightViewController



-(void)viewDidLoad {

[countdownLabel setFont:[UIFont fontWithName:@"DS-Digital" size:64.0]];
countdownLabel.text = @"I0A0IN6";
[super viewDidLoad];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceO rientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)dealloc {
[super dealloc];
}

-(void)updateLabel {
NSDate* now = [NSDate date];

int hour = 23 - (int)[[now dateWithCalendarFormat:nil timeZone:nil] hourOfDay];
int min = 59 - (int)[[now dateWithCalendarFormat:nil timeZone:nil] minuteOfHour];
int sec = 59 - (int)[[now dateWithCalendarFormat:nil timeZone:nil] secondOfMinute];
countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min,sec];

}


@end


------

// MinutesToMidnightViewController.h

#import <UIKit/UIKit.h>

@interface MinutesToMidnightViewController : UIViewController {
IBOutlet UILabel *countdownLabel;
}

-(void)updateLabel;

@end

-----

// MinutesToMidnightAppDelegate.m

#import "MinutesToMidnightAppDelegate.h"
#import "MinutesToMidnightViewController.h"

@implementation MinutesToMidnightAppDelegate

@synthesize window;
@synthesize viewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}

- (void)onTimer {
[viewController updateLabel];
}

- (void)applicationWillTerminate:(UIApplication *)application {
[timer invalidate];
}

- (void)dealloc {
[timer release];
[viewController release];
[window release];
[super dealloc];
}


@end

-----

// MinutesToMidnightAppDelegate.h

#import <UIKit/UIKit.h>

@class MinutesToMidnightViewController;

@interface MinutesToMidnightAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet MinutesToMidnightViewController *viewController;
NSTimer *timer;
}
-(void)onTimer;
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) MinutesToMidnightViewController *viewController;

@end

Jan 28, 2010 9:18 PM in response to kneedragger101

kneedragger101 wrote:
This is all the code.... I was following the tutorial found here: http://appsamuck.com/day1.html
[countdownLabel setFont:[UIFont fontWithName:@"DS-Digital" size:64.0]];


For what it's worth, I downloaded the Xcode project off that page and compiled it. They have a different font name in their code. If I put in your code, I also get an exception, though it specifically mentions not being able to find the font.

One thing you could do is download the Xcode project and open it up and look and see if you can figure out the difference between your project and theirs. Alternatively, if you can find a place to post your Xcode project so people can download it, that can be helpful, too.

Finally, when you post code, put it between {code} tags. In other words, post it like this:

{ code} some code
some other code
some more code
{ code}

That makes it easier to read since the forum software leaves some of the special characters alone.

charlie

Jan 29, 2010 10:06 AM in response to kneedragger101

Here is the error I am getting when I use a breakpoint.

The Debugger has exited due to signal 15 (SIGTERM).The Debugger has exited due to signal 15 (SIGTERM).

[Session started at 2010-01-29 13:04:25 -0500.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 22612.
Pending breakpoint 1 - ""CountdownViewController.m":16" resolved
2010-01-29 13:04:27.841 Countdown[22612:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "CountdownViewController" nib but the view outlet was not set.'
2010-01-29 13:04:27.843 Countdown[22612:207] Stack: (
29258843,
2507441417,
29342779,
29342618,
3215930,
3209275,
3208993,
9075,
2692639,
2730506,
2718600,
2701011,
2728117,
37355217,
29043584,
29039688,
2694761,
2732035,
8900,
8754
)
(gdb)

Jan 29, 2010 10:35 AM in response to kneedragger101

Ok, good news! I clicked on File's Owner, opened the Connection Inspector, added a View Controller to my Documents window and then with the File's Owner still selected dragged my view to my View Controller. I got the idea here > http://bill.dudney.net/roller/objc/entry/demystifyingview_controllers_andviews

Now I was showing an error in the debugger because of the font. I changed the font to Helvetica and it worked as expected! I installed the font on my Mac and I can see it int the Font window inside Interface Builder but I am getting this error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'


Any idea how to solve this?

Jan 29, 2010 6:55 PM in response to kneedragger101

kneedragger101 wrote:
Now I was showing an error in the debugger because of the font. I changed the font to Helvetica and it worked as expected! I installed the font on my Mac and I can see it int the Font window inside Interface Builder but I am getting this error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'

Any idea how to solve this?


A Google search for iphone app custom font shows that you've now moved out of "simple" land and into more treacherous waters.

There's a post at Stack Overflow. Another on a blog. And another blog post.

Also, keep in mind that if you want to distribute the app you're making, you'll need to make sure you have the legal right to distribute the font. If it's a custom font you created yourself, then that wouldn't be a problem.

charlie

Feb 1, 2010 8:08 PM in response to Charles Minow

So I have seen this code over at Stack Overflow to add a custom font to my application. I'm not concerned with using this for distribution I just want to know how to do it...


BOOL GSFontAddFromFile(const char * path);
NSUInteger loadFonts()
{
NSUInteger newFontCount = 0;
for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:nil])
newFontCount += GSFontAddFromFile([fontFile UTF8String]);
return newFontCount;
}


Once fonts are loaded, they can be used just like the Apple-provided fonts:


NSLog(@"Available Font Families: %@", [UIFont familyNames]);
[label setFont:[UIFont fontWithName:@"Consolas" size:20.0f]];

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Simple issue with basic iPhone application.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.