如何根据索引将值放入特定行的特定文本字段中?我的结果只在底部或最后一个单元格更新......
目前,它要求自己获取当前值。我对这个问题的唯一问题是它不会更新当前行,而是更新索引路径的最后一行。
.h 文件
//当label1和label 2连接时会导致程序崩溃。连接不能将原型插座作为目标
@property (nonatomic, strong) IBOutlet UILabel *label1; //not connected
@property (nonatomic, strong) IBOutlet UILabel *label2; //not connected
@property (nonatomic, weak) IBOutlet UIStepper *stepper; // not conneted
-(IBAction)stepperChangedValue:(UIStepper *)sender; //connected to uistepper
.m 文件
-(IBAction)stepperChangedValue:(UIStepper *)sender{
//my incremental number is here
NSInteger i = [sender value];
NSLog(@"value: %i",i);
UITextField *textField = (UITextField*)[self.view viewWithTag:2];
textField.text = [NSString stringWithFormat:@"%d",i ];
//find row #
UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"value: %i",indexPath.row); //I have my row index here
//How do I put my sender value back into the correct row of my table?
}
// Return number of sections in table (always 1 for this demo!)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [myData count];
}
// Return the amount of items in our table (the total items in our array above)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myData count];
}
// Return a cell for the table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// A cell identifier which matches our identifier in IB
static NSString *CellIdentifier = @"StepperCell";
// Create or reuse a cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Get the cell label using it's tag and set it
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
[cellLabel setText:[myData objectAtIndex:indexPath.row]];
// get the cell label using it's tag and set it
UILabel *cellLabel2 = (UILabel *)[cell viewWithTag:2];
[cellLabel2 setText:@"0"];
return cell;
}
多谢你们!我很感激。