IPHONE的問題...我嘗試了幾個不同的模板和其他人的幫助,但我似乎無法得到這個工作,它不應該太難了。我想添加一個帶有「3組件」的UIPickerView,每個組件都是數字值(例如,它們可以在50-100之間選擇),並顯示它們在msg窗口中選擇的內容。 (計算部分我會後來弄清楚,但首先我需要讓組件正確註冊第三列,遇到問題後出現問題....任何想法?如何創建一個3組件UIPickerView(模板任何人???)iPhone
*我不是最有經驗的,並聽說這是一個很好的地方,可以從一些非常聰明的人那裏得到答案,我真的很感謝任何人提供的幫助或任何人提供的「模板」大綱,以供任何人使用3個組件的UIPickerView ...感謝高級>>> Lawrence
這是我的ViewController.m代碼:
#import "DoubleComponentPickerViewController.h"
@implementation DoubleComponentPickerViewController
@synthesize doublePicker;
@synthesize oneTypes;
@synthesize twoTypes;
@synthesize threeTypes;
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
-(IBAction)buttonPressed
{
NSInteger oneRow = [doublePicker selectedRowInComponent:
kOneComponent];
NSInteger twoRow = [doublePicker selectedRowInComponent:
kTwoComponent];
NSInteger threeRow = [doublePicker selectedRowInComponent:
kThreeComponent];
NSString *one = [oneTypes objectAtIndex:oneRow];
NSString *two = [twoTypes objectAtIndex:twoRow];
NSString *three = [threeTypes objectAtIndex:threeRow];
NSString *message = [[NSString alloc] initWithFormat:
@"First = %@ Second = %@ Third = %@",one, two, three];
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Please Confirm Numbers" message:message delegate:nil cancelButtonTitle:@"Confirm" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSArray *oneArray = [[NSArray alloc] initWithObjects:
@"91",@"92",@"93",@"94",@"95",@"96",nil];
self.oneTypes = oneArray;
[oneArray release];
NSArray *twoArray = [[NSArray alloc] initWithObjects:
@"97",@"98",@"99",@"100",@"101",@"102",@"103", nil];
self.twoTypes = twoArray;
[twoArray release];
NSArray *threeArray = [[NSArray alloc] initWithObjects:
@"102",@"103",@"104",@"105",@"106",@"107", nil];
self.threeTypes = threeArray;
[threeArray release];
[super viewDidLoad];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// 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)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[doublePicker release];
[oneTypes release];
[twoTypes release];
[threeTypes release];
[super dealloc];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (component == kOneComponent)
return[self.oneTypes count];
return[self.twoTypes count];
return[self.threeTypes count];
if (component == kTwoComponent)
return[self.oneTypes count];
return[self.twoTypes count];
return[self.threeTypes count];
if (component == kThreeComponent)
return[self.oneTypes count];
return[self.twoTypes count];
return[self.threeTypes count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (component == kThreeComponent)
return [self. threeTypes objectAtIndex:row];
return [self. twoTypes objectAtIndex:row];
return [self. oneTypes objectAtIndex:row];
}
@end
的文檔是你的朋友。學會傾聽你的朋友。 – dasdom