Я работаю над uipicker
внутри uitableview's prototype cell
где я создаю uilabel
. Теперь я добавляю выбранное значение строки выбора выбора на ярлыке, но моя проблема заключается в том, что когда я выбираю строку из представления выбора, все метки обновляются.Как добавить значение uipickerview выбранного значения строки в uilabel?
Значение должно быть обновлено в выбранной строке на uilabel
. Вот мой код и снятый снимок экрана.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
UILabel *lable = (UILabel*)[cell viewWithTag:111];
lable.tag = indexPath.row;
lable.text = value;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
_nameLabel.text =nil;
[self.mytableview reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:NO];
[self bringUpPickerViewWithRow:indexPath];
}
- (void)bringUpPickerViewWithRow:(NSIndexPath*)indexPath
{
UITableViewCell *currentCellSelected = [self.mytableview cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
self.pickerView.hidden = NO;
self.pickerView.center = (CGPoint) { currentCellSelected.frame.size.width/2, self.mytableview.frame.origin.y + currentCellSelected.frame.size.height*4};
self.mytableview.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.mytableview setNeedsDisplay];
}
completion:nil];
}
- (void)hidePickerView
{
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
self.pickerView.center = (CGPoint){160, 800};
}
completion:^(BOOL finished)
{
self.pickerView.hidden = YES;
[self.mytableview reloadData];
}];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return _countingarray.count;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component
{
[self.mytableview reloadData];
[self hidePickerView];
NSLog(@"row selected:%ld", (long)row);
NSString *resultString = _countingarray[row];
value = resultString;
}
- (NSString*) pickerView:(UIPickerView *)pickerView titleForRow: (NSInteger)row forComponent:(NSInteger)component
{
//return [NSString stringWithFormat:@"%d", row+1];
return _countingarray[row];
}
- (IBAction)editbuttonclicked:(id)sender {
if([self.mytableview isEditing] == NO){
//[self.mytableview settitle:@"Done"];
//set the table to editing mode
[self.mytableview setEditing:YES animated:YES];
}else
{
//we are currently in editing mode
//change the button text back to Edit
//[self.editbutton setTitle:@"Edit"];
//take the table out of edit mode
[self.mytableview setEditing:NO animated:YES];
}
}
-(void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[myData removeObjectAtIndex:indexPath.row];
[self.mytableview deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
кто-то помочь мне плз –
у вас уже есть 'myData', который вы используете чтобы определить, сколько строк должно отображаться в таблицеView, вам, вероятно, нужно, чтобы все, что находится в этом массиве, определяло текст, показанный для каждой метки. После того, как вы это сделали, вам больше нужно «значение», но после этого нужно будет обрабатывать данные в этом массиве и «reloadData». – luk2302
как объявляется значение? –