Reputation: 305
I am getting a value from uipickerview and set it on uilabel of uitableviewcell, now i want that if i again get value from picker view than add it to previous value.
Here is my code for cell index:
- (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;
}
This is the code for picker view form where i get value;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[self.mytableview reloadData];
[self hidePickerView];
NSLog(@"row selected:%ld", (long)row);
value = _countingarray[row];
}
Upvotes: 1
Views: 121
Reputation: 1265
-(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;
}
Upvotes: 3
Reputation: 1214
- (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];
}
Upvotes: 0