Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone中将textfield值设置为picker?_Iphone_Objective C - Fatal编程技术网

如何在iPhone中将textfield值设置为picker?

如何在iPhone中将textfield值设置为picker?,iphone,objective-c,Iphone,Objective C,我有一个应用程序,其中有一个文本字段,我在其中显示数据库中的值。文本字段旁边有一个按钮。我有一个选择器,其中包含4个值,即自定义、行走、跑步、慢跑 如果文本字段包含一个值,即如果其中包含“Walk”,则单击按钮,我将显示填充了4个值的选择器。但我的问题是,当点击按钮时,应该在选择器上设置值“Walk” 这是我的密码 - (void)viewDidLoad { [super viewDidLoad]; currentarray = [[NSMutableArray alloc] i

我有一个应用程序,其中有一个文本字段,我在其中显示数据库中的值。文本字段旁边有一个按钮。我有一个选择器,其中包含4个值,即自定义、行走、跑步、慢跑

如果文本字段包含一个值,即如果其中包含“Walk”,则单击按钮,我将显示填充了4个值的选择器。但我的问题是,当点击按钮时,应该在选择器上设置值“Walk”

这是我的密码

- (void)viewDidLoad
{
    [super viewDidLoad];
    currentarray = [[NSMutableArray alloc] initWithObjects:@"Custom",@"Walk",@"Run",@"Jog",nil];
       // Do any additional setup after loading the view from its nib.
}
这是我的按钮操作,单击该按钮将打开选择器:

-(IBAction)choose
{
    actionsheet = [[UIActionSheet alloc]initWithTitle:[currentarray objectAtIndex:0] delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];

    [actionsheet setTitle:@"Picker"];

    pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 0, 0)];
    pickerView.dataSource=self;
    pickerView.delegate=self;
    pickerView.showsSelectionIndicator=YES;
    [actionsheet addSubview:pickerView];
    [actionsheet showInView:self.view];
    [pickerView selectRow:[txtTextfield.text intValue ]-1 inComponent:0 animated:YES];        
    [actionsheet showInView:[[UIApplication sharedApplication]keyWindow]];
    [actionsheet setBounds:CGRectMake(0, 0, 320, 485)];        
}

-(NSString*)pickerView:(UIPickerView*)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{      
    NSString *string;
    string = [NSString stringWithFormat:@"%@",[currentarray objectAtIndex:row]];
    return string;      
}

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

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

可以这样设置pickerView

 [pickerView setObject:textField.text];
看看下面的链接