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 07-09-2010, 06:14 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default UIPicker Problem

Hello,

I'm trying to implement UIPicker as a subview of a current ViewController. When the user taps on a textfield, the keyboard popups instead of the UIPicker. I was pointed to the following tutorial as a guide:

UIPickerView - Creating a simple picker view - iPhone SDK Articles

My code is as follows:

NewWorkoutViewController.h
Code:
@interface NewWorkoutViewController : UIViewController  {
	IBOutlet UIBarItem *saveButton;
	IBOutlet UIBarItem *backButton;
	
	IBOutlet UILabel *time;
	//IBOutlet UITextView *routePicker;
	
	IBOutlet UIPickerView *pickerView;
	
	int counterInt;
	NSTimer *myTimer;
	
	NSInteger *startInterval;
	NSInteger *stopInterval;
	NSInteger *elapsedInterval;
}

@property (retain,nonatomic) NSTimer *myTimer;

-(IBAction)backButton;
-(IBAction)saveButton;
-(IBAction)mapButton:(id) sender;
-(IBAction)statisticsButton:(id) sender;

-(IBAction)startTimerButton;
-(IBAction)stopTimerButton;

-(IBAction)routePicker;

-(void)showActivity;

@end
NewWorkoutViewController.m
Code:
#import "NewWorkoutViewController.h"
#import "StatisticsViewController.h"

@implementation NewWorkoutViewController

@synthesize myTimer;

-(void)routePicker
{
	PickerViewController *pvController = [[PickerViewController alloc] initWithNibName:@"PickerView" bundle:[NSBundle mainBundle]];	
	[self presentModalViewController:pvController animated:YES];
}


-(void)applicationDidFinishLaunching:(UIApplication *)application
{	
	pvController = [[PickerViewController alloc] initWithNibName:@"PickerView" bundle:[NSBundle mainBundle]];
	[window addSubview:pvController.view];
	
    // Override point for customization after application launch
    [window makeKeyAndVisible];	
}


- (void)dealloc {
	[myTimer release];
    [super dealloc];
}
@end
PickerViewController.h
Code:
#import <UIKit/UIKit.h>

@interface PickerViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>{

	IBOutlet UIPickerView *pickerView;
	NSMutableArray *list;
}

@end
PickerViewController.m
Code:
#import "PickerViewController.h"

@implementation PickerViewController


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


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


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


-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
	NSLog(@"Selected item: %@ index of selected item: %i",[list objectAtIndex:row], row);
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	list = [[NSMutableArray alloc] init];
	[list addObject:@"red"];
	[list addObject:@"blue"];
	[list addObject:@"yellow"];
	[list addObject:@"pink"];
}

- (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)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[list release];
    [super dealloc];
}
At the moment pvController is giving me an error as its not declared, the tutorial has the following code in place:

Code:
@class PickerViewController;

@interface PickerViewAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	PickerViewController *pvController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end
My PickerView is not setup as the AppDelegate, its a ViewController, so I'm not sure what to do ?

Regards, Stephen

Last edited by stephen; 07-09-2010 at 06:46 AM.
stephen is offline   Reply With Quote
Old 07-09-2010, 06:22 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Please ignore this for the moment, I just saw something I forgot to do.

Sorry for the hassle....Stephen

Last edited by stephen; 07-09-2010 at 06:44 AM.
stephen is offline   Reply With Quote
Old 07-09-2010, 06:45 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

I've updated the my code above with the problem.
stephen 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: 339
15 members and 324 guests
akphyo, alexP, cgokey, EXOPTENDAELAX, flamingliquid, GHuebner, guusleijsten, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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