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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2009, 07:54 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 4
Exclamation .Plist Key Value into Label

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
teeeroy is offline   Reply With Quote
Old 12-24-2009, 08:48 PM   #2 (permalink)
Shmoopi LLC
 
Shmoopi's Avatar
 
Join Date: Jun 2009
Location: Virginia
Posts: 203
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
Reply

Bookmarks

Tags
.plist, label, nsstring, playlist, uitabbarcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 251
16 members and 235 guests
@sandris, ADY, Alsahir, cacao, dacapo, Dani77, Desert Diva, djohnson, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0