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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-2010, 02:54 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 48
benblanchard is on a distinguished road
Default Picker and Label

Hello!

I'm quite new, so, if this is in the wrong place, I'm sorry.

Heres the problem:

I have started on a little app to improve my skills (I'm just a beginner!), and so far, I have created a Picker with quite a few rows in. Each of these rows displays a different language. Basically, they say "English", "French", "Spanish" etc.

What I want to do is have a Label that displays a piece of text in the language that is selected in the Picker. So basically, if the picker selects "Spanish", I want a piece of text displayed in the label. Whereas, when "French" is selected, it displays another piece of text.

At the moment, I have got the label to display the text in the Picker already. So it displays "Spanish" when the row on the Picker is "Spanish", but ultimately, I would like it to display a different piece of text, that is in Spanish.

Hopefully you understand me.

If it helps, heres my code so far . . .

In the .h file:
Code:
#import <UIKit/UIKit.h>

@interface HILPickerViewController : UIViewController {
	IBOutlet UIPickerView *picker;
	NSArray *languagesColumn;
	
	IBOutlet UILabel *helloLabel;
}

@property (nonatomic, retain) IBOutlet UIPickerView *picker;
@property (nonatomic, retain) NSArray *languagesColumn;
@property (nonatomic, retain) IBOutlet UILabel *helloLabel;


@end

In the .m file:
Code:
#import "HILPickerViewController.h"

@implementation HILPickerViewController

@synthesize helloLabel;
@synthesize picker;
@synthesize languagesColumn;

- (void)viewDidLoad {
    [super viewDidLoad];
	NSArray *array = [[NSArray alloc] 
			  initWithObjects:@"English",
						@"Dutch",
					  	@"French",
					  	@"German",
					  	@"Greek",
					  	@"Italian",
					  	@"Japanese",
					  	@"Korean",
					  	@"Polish",
					  	@"Portuguese",
					  	@"Russian",
					  	@"Spanish",
					        nil];
	self.languagesColumn = array;
	[array release];
}


-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
	return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
	return [languagesColumn count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
	return [languagesColumn objectAtIndex:row];	
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	
		helloLabel.text = [languagesColumn objectAtIndex:row];
	
}
benblanchard is offline   Reply With Quote
Old 08-04-2010, 03:18 PM   #2 (permalink)
miv
Registered Member
 
Join Date: Aug 2009
Posts: 12
miv is on a distinguished road
Default

Hi,
if I take it well, you need this:

.h file:
NSArray *another_array;

.m file:
- (void)viewDidLoad {
...
NSArray *array = [[NSArray alloc] initWithObjects:@"English", @"Dutch", @"French", @"German", @"Greek", @"Italian", @"Japanese", @"Korean", @"Polish", @"Portuguese", @"Russian", @"Spanish", nil];

another_array = [[NSArray alloc]
initWithObjects:@"text when select: English",
@"text when select: Dutch",
@"text when select: French",
@"text when select: German",
@"text when select: Greek",
@"text when select: Italian",
@"text when select: Japanese",
@"text when select: Korean",
@"text when select: Polish",
@"text when select: Portuguese",
@"text when select: Russian",
@"text when select: Spanish",
nil];
...
}

- (void)pickerViewUIPickerView *)thePickerView didSelectRowNSInteger)row inComponentNSInteger)component {
// helloLabel.text = [languagesColumn objectAtIndex:row];
helloLabel.text = [another_array objectAtIndex:row];
}

Miv
miv is offline   Reply With Quote
Old 08-05-2010, 02:23 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 48
benblanchard is on a distinguished road
Default

Thankyou!

That worked Perfectly!

Do I make the cheque out to Miv?!

But, thankyou very much!
benblanchard is offline   Reply With Quote
Reply

Bookmarks

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: 324
9 members and 315 guests
alexP, arash5500, gordo26, mediaspree, nobstudio, rayjeong, Sloshmonster, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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