我在每个单元格中有一个带有自定义单元格的 TableView 我有一个文本字段,当我更改 textField 的值时,另一个单元格中的另一个文本字段被更改。
例子:
我更改了单元格 0 中的值,单元格 8 也更改了
tableView cellForRowAtIndexPath 方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Disbursment_CustomCell";
Disbursment_CustomCell *cell = (Disbursment_CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Disbursment_CustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
}
cell.disbursmentNumber_label.text = [[NSString alloc] initWithFormat:@"%d",[indexPath row]];
return cell;
}
CustomCell.m
@implementation Disbursment_CustomCell
@synthesize dateDisbursment_textField,pourcentage_Slider,pourcentage_textField;
-(IBAction) sliderChanged:(id) sender{
self.pourcentage_textField.text=[NSString stringWithFormat:@"%li", lroundf(self.pourcentage_Slider.value)];
}
- (void)handlePickerChanged:(id)sender
{
UIDatePicker *picker = (UIDatePicker *)sender;
NSDate *myDate = picker.date;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd'/'MM'/'yyyy"];
NSString *prettyVersion = [dateFormat stringFromDate:myDate];
self.dateDisbursment_textField.text = prettyVersion;
}
- (IBAction)didBegin:(id)sender {
self.picker = [[UIDatePicker alloc] init];
self.picker.datePickerMode = UIDatePickerModeDate;
[self.picker addTarget:self action:@selector(handlePickerChanged:) forControlEvents:UIControlEventValueChanged];
dateDisbursment_textField.inputView = self.picker ;
}
@end