gpt4 book ai didi

ios - 如何为 iOS 7 创建弹出式 uipicker 和 uitextfield?

转载 作者:行者123 更新时间:2023-11-28 18:35:46 25 4
gpt4 key购买 nike

我需要将选择器添加到我的文本框,但不知道如何让它们工作。我已经浏览了很多教程,向您展示了如何从头开始,如果您有一个现有的应用程序并且想要添加功能,那么这些教程就没什么用了,在大多数情况下它们不是很有帮助。

我正在寻找与下图非常相似的东西。下面显示的显然是一个 UIDatepicker,但理想情况下是

I'm looking for a custom picker for "place", "term", and "gate".

所以现在,跳过 UIDatepicker 项,关注自定义选择器项。

One more thing, this is iOS7, and I am using storyboards AND arc!

popup pickerview

我遇到了这个 ( http://www.youtube.com/watch?v=BtmQp5aP304 ),这真的很有帮助,但它又是从头开始的。我想不通的是如何在我现有的代码中实现它。所以我正在寻找一个演练,一个教程,有人可以指点我让我开始。

There is this on stackoverflow -> how to pop up datePicker when text filed click and disappear when editing done

这给了我一些想法,但不是我正在寻找的东西,尝试了这些建议,但最终出现的错误比其他任何方法都多。

谢谢。

最佳答案

 @interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@implementation ViewController
{
UIPopoverController *popoverController;
NSString *currentPick;
….
}
.
.
.
-(void)makePicker{

UIPickerView *picker = [[[UIPickerView alloc]init]autorelease];
picker.frame = CGRectMake(0, 50, 320, 1000);
picker.showsSelectionIndicator = YES;
picker.delegate = self;
UIButton *done = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[done setBackgroundImage:[UIImage imageNamed:@"Save.png"] forState:UIControlStateNormal];
[done setFrame:CGRectMake(260, 10, 50, 30)];
[done addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
UIButton *cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cancel setBackgroundImage:[UIImage imageNamed:@"Cancel.png"] forState:UIControlStateNormal];
[cancel setFrame:CGRectMake(10, 10, 50, 30)];
[cancel addTarget:self action:@selector(cancelButton:) forControlEvents:UIControlEventTouchUpInside];


if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
UIActionSheet *pickerAction = [[[UIActionSheet alloc]initWithTitle:[cells objectAtIndex:indexPath.section] delegate:self cancelButtonTitle:nil destructiveButtonTitle:Nil otherButtonTitles:nil]autorelease];
[pickerAction addSubview:picker];
[pickerAction addSubview:done];
[pickerAction addSubview:cancel];
[pickerAction showInView:self.view];
pickerAction.frame = CGRectMake(0,[UIScreen mainScreen].bounds.size.height - 330,320, 350);
}else
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
[popoverView addSubview:picker];
[popoverView addSubview:done];
[popoverView addSubview:cancel];
[popoverContent.view addSubview:popoverView];
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:<your frame> inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 260);
[popoverView release];
[popoverContent release];

}
}
.
.
.

// mainArray here is a NSArray of several arrays, these arrays contain the titles for different selections… e.g. @[fontArray,colourArray,nameArray]

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

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

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [[mainArray objectAtIndex:clickedAt] objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
currentPick = [[mainArray objectAtIndex:clickedAt] objectAtIndex:row];
}


- (void)doneButton:(UIButton *)button
{
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
UIActionSheet *as = (UIActionSheet *)[button superview];
[as dismissWithClickedButtonIndex:0 animated:YES];
}
else
[popoverController dismissPopoverAnimated:YES];

// save your selections here using currentPick object
}

- (void)cancelButton:(UIButton *)button
{
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
UIActionSheet *as = (UIActionSheet *)[button superview];
[as dismissWithClickedButtonIndex:0 animated:YES];
}
else
[popoverController dismissPopoverAnimated:YES];
}

享受您的选择器 ;)

关于ios - 如何为 iOS 7 创建弹出式 uipicker 和 uitextfield?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19564418/

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