There are similar questions already asked many times and have referred many solutions but none worked for me as they were addressing fixed number of cells and I have dynamic number of cells. Here is the problem:
It is in Objective-C. I've tableview which has dynamic number of rows(user can add more cells or remove cells as per requirement) and each row contains 3 textfields and at the end I want to get data from that textfields and save them. Getting data from all textfields is working perfectly but here comes main problem when I add data into any row(3 textfields) it's getting repeat when I scroll it.
Here is code:
-(void)textFieldDidEndEditing:(UITextField *)textField{
if ([_txtNumbers resignFirstResponder]) {
totalIndex = [_txtNumbers.text integerValue];
[_tblContacts reloadData];
}
}
- (IBAction)onAddCellClicked:(id)sender {
totalIndex = [_txtNumbers.text integerValue];
totalIndex = totalIndex + 1;
_txtNumbers.text = [NSString stringWithFormat:@"%ld",(long)totalIndex];
[_tblContacts reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return totalIndex;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"InviteEmailTableViewCell";
InviteEmailTableViewCell *cell = [self.tblContacts dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.txtName.delegate = self;
cell.txtTell.delegate = self;
cell.txtEmail.delegate = self;
UIToolbar *numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[numberToolbar setTintColor:kShadowColor1];
[numberToolbar setBarTintColor:[UIColor blackColor]];
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad:)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad:)],
nil];
cell.txtTell.inputAccessoryView = numberToolbar;
[cell.txtName setTag:indexPath.row];
[cell.txtTell setTag:indexPath.row];
[cell.txtEmail setTag:indexPath.row];
return cell;
}
what to do next here?