インデックスに従って、特定の行の特定のテキストフィールドに値をどのように配置しますか? 私の結果は一番下または最後のセルでのみ更新されます...
現在、現在の値を自分自身で呼び出します。この問題に関する私の唯一の問題は、現在の行ではなく、インデックス パスの最後の行が更新されることです。
.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;
}
みんなありがとう!それは有り難いです。