0
데이터베이스에서 값을 표시 할 텍스트 필드가있는 응용 프로그램이 있습니다. 텍스트 필드 외에 버튼이 있습니다. 4 가지 값을 포함하는 선택 도구가 Custom, Walk, Run, Jog입니다.iPhone에서 텍스트 필드 값을 선택기로 설정하는 방법은 무엇입니까?
텍스트 필드에 값이 들어있는 경우 즉 '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];
}