I establish a tableview , but I want to click direct cell show the picker to select.
Then the selected value will show in the cell label component.
But I had try to labelName.text = picker
. or call picker in the didSelectRowAtIndexPath
. It's not showing the picker.
my code is below
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MotDeteTableViewCell";
cell = (MotDeteTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if( cell == nil )
{
cell = [[MotDeteTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.motTableTitleLabel.text = [tableDatasAry objectAtIndex:indexPath.row];
if( indexPath.row == 0)
{
}
else if ( indexPath.row == 1)
{
myLb = [ [UILabel alloc ] initWithFrame:CGRectMake(_motTableView.frame.size.width -50 , 0.0, 70.0, 40.0) ];
// ------- I expect click the picker value will show in myLb label
myLb.text = @"picker will show value";
[cell addSubview:myLb];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
break;
case 1:
// -------- I had try put settingPickeProperty in here or viewdidload
[self settingPickeProperty];
break;
default:
break;
}
}
#pragma mark - settting picker datas
-(void) settingPickeProperty
{
picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
picker .delegate = self;
picker .dataSource = self;
[ picker setShowsSelectionIndicator:YES];
// -------if i use textfield the picker had correct show. but i want to click cell show the picker, I don't know how to set xxxx = picker;
_pickertf.inputView = picker ;
UIToolbar* mypickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
mypickerToolbar.barStyle = UIBarStyleDefault;
[mypickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"done" style:UIBarButtonItemStyleBordered target:self action:@selector(pickerDoneClicked)];
[barItems addObject:doneBtn];
[mypickerToolbar setItems:barItems animated:YES];
// ------ if use textfield had correct...
_pickertf.inputAccessoryView = mypickerToolbar;
}
-(void)pickerDoneClicked
{
NSLog(@"Done Clicked");
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
return [titleAry count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [titleAry objectAtIndex:row];
}
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
}
It's my code offer every reference.
How to achieve click tableview cell to show the picker then select picker value show in myLb?