gpt4 book ai didi

iphone - 如何创建 3 组件 UIPickerView(模板任何人???)iPhone

转载 作者:行者123 更新时间:2023-12-03 21:06:32 25 4
gpt4 key购买 nike

IPHONE 问题...我尝试了几种不同的模板并得到了其他人的帮助,但我似乎无法使其正常工作,而且应该不会太困难。我想添加一个带有“3 个组件”的 UIPickerView,每个组件都是数值(例如,他们在每个组件中选择 50-100 之间),并且它显示他们在消息窗口中选择的内容。 (计算部分我稍后会弄清楚,但首先我需要让组件正确注册第三列,出现一个又一个问题......有什么想法吗?

* 我不是最有经验的,并且听说这是从一些非常聪明的人那里获得答案的好地方。我真的很感谢任何人可以为 3 组件 UIPickerView 提供的任何帮助或大纲"template"...提前感谢>>>劳伦斯

这是我的 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

最佳答案

您可以实现数据源方法

// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

然后就可以实现委托(delegate)方法了

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

关于iphone - 如何创建 3 组件 UIPickerView(模板任何人???)iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com