我从uipickerview获取一个值并将其设置在uitableviewcell的uilabel上,现在我希望如果我再次从picker视图获取值而不是将其添加到之前的值。
这是我的单元索引代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
UitableviewcellTableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
if(position == indexPath.row){
NSString *old = Cell.nameLabel.text = value;
int val = [old intValue];
NSLog(@"val %d", val);
// Cell.nameLabel.text = [NSString stringWithFormat: @"%d", val+];
}else{
Cell.nameLabel.text = @"value";
}
NSLog(@"Position :- %ld %d", (long)indexPath.row, position);
return Cell;
}
这是我获得价值的选择器视图表单的代码;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[self.mytableview reloadData];
[self hidePickerView];
NSLog(@"row selected:%ld", (long)row);
value = _countingarray[row];
}
答案 0 :(得分:3)
-(void)viewDidLoad
{
value = @"0";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"row selected:%ld", (long)row);
value = [NSString stringWithFormat:@"%d",[value intval] + [_countingarray[row] intval]];
[self.mytableview reloadData];
[self hidePickerView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UitableviewcellTableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
Cell.nameLabel.text = value;
NSLog(@"%@", value);
return Cell;
}
答案 1 :(得分:0)
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"row selected:%ld", (long)row);
yourLabel.text = [yourLabel.text intVal] + [_countingarray[row] intVal];
[self.mytableview reloadData];
[self hidePickerView];
}