Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 12-24-2009, 07:48 PM   #2 (permalink)
Shmoopi
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 213
Shmoopi is on a distinguished road
Default

Quote:
Originally Posted by teeeroy View Post
Hey I'm trying to make a joke shuffler app but can't the simple part of my code correct. Here it is...

Code:
#import "JokesAppDelegate.h"

@implementation JokesAppDelegate

- (void)readPlist
{
	NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Jokes" ofType:@"plist"];
    self.data = [NSArray arrayWithContentsOfFile:dataPath];	
	
	NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:dataPath];
	
	value = [plistDict objectForKey:@"test"];
	
	/* You could now call the string "value" from somewhere to return the value of the string in the .plist specified, for the specified key. */
}


@synthesize window;
@synthesize tabBarController;
@synthesize value;



- (void)applicationDidFinishLaunching:(UIApplication *)application {
	label.text = value;
And Here's the header

Code:
#import <UIKit/UIKit.h>


@interface JokesAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
	IBOutlet UILabel *label;
	NSString *value;
	NSArray *data;
	}

@property (nonatomic, retain)	NSString	*value;
@property (nonatomic, retain) NSArray *data;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end
Above, I am trying to find the key "test" in my jokes.plist and get it's value to be displayed in the label but nothing is showing up on the label when I Build and Go.

P.S. As obvious from above I am using a tabbarcontroller

Pls Help
You've got everything right except that you're not setting the label's text in the readplist method. Simply move this code:
Code:
label.text = value;
from the applicationDidFinishLaunching method into the readplist method. It should look like this:
Code:
#import "JokesAppDelegate.h"

@implementation JokesAppDelegate

- (void)readPlist
{
	NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Jokes" ofType:@"plist"];
    self.data = [NSArray arrayWithContentsOfFile:dataPath];	
	
	NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:dataPath];
	
	value = [plistDict objectForKey:@"test"];
	
        label.text = value;

	/* You could now call the string "value" from somewhere to return the value of the string in the .plist specified, for the specified key. */
}


@synthesize window;
@synthesize tabBarController;
@synthesize value;



- (void)applicationDidFinishLaunching:(UIApplication *)application {
Shmoopi is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,421
Threads: 94,016
Posts: 402,539
Top Poster: BrianSlick (7,978)
Welcome to our newest member, maryleeag34
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:45 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.