I am making a table object which by a swipe gesture changes the displayed values to completely different ones. This works because there is a UIPageControl which shows which set must be displayed on the table. The code involves a mutable array containing mutable arrays at the index of the page. For example the first page gives the mutable array at index 0. These mutable arrays contained, contain the table objects and give out the appropriate value to the table by referring to the index of the cell. What happens however is that when the table contains more than 1 cells, it mixes the objects of arrays of different pages, something that shouldn't happen as these are different arrays. The code is here:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
startDtLbl = [[UITextField alloc] initWithFrame:CGRectMake(10, 11, _answerTable.frame.size.width, 25)];
startDtLbl.backgroundColor = [UIColor clearColor];
startDtLbl.tag = 1;
startDtLbl.returnKeyType = UIReturnKeyDone;
startDtLbl.delegate = self
[cell.contentView addSubview:startDtLbl];
}
else {
startDtLbl = [cell.contentView viewWithTag:1];
}
startDtLbl.text = [[answers objectAtIndex:_pageView.currentPage] objectAtIndex:(indexPath.row)];
return cell; }
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
UITableViewCell *textCell = [[textField superview] superview];
NSIndexPath *indexPathOfText = [_answerTable indexPathForCell:textCell];
[switchStates replaceObjectAtIndex:indexPathOfText.row withObject:textField.text];
[answers replaceObjectAtIndex:_pageView.currentPage withObject:switchStates];
[textField resignFirstResponder];
return YES; }
The bool method just assigns the text to the arrays and through logging I've found that this works perfectly. Also in case you haven't noticed, the cells contain TextFields. Any ideas on what could be wrong?