I have an array, we'll call it itemsArray, that contains instances of a class called Item. These items have properties of length, width, and height. itemsArray is also nested within another class (questionnaire) that also has a property called activeItem. Basically, the activeItem is an integer that returns a value that corresponds to the index of the item in itemsArray that is being edited at the time. Therefore, if I wanted to update the second item in itemsArray, I would set activeItem to 1 and go from there.
Now, I need to populate these length, width, and height properties of the items in itemsArray. To do so, I'm creating a tableView with a customized UITableViewCell. This UITableViewCell, let's call it CustomTableViewCell, has 3 UITextField properties corresponding to 3 UITextFields that I put on the storyboard, lengthField, widthField, and heightField. I'm having some trouble getting the values typed into the textfields to store with their corresponding instances of item. Here's some code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
self.cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"quantityCell"];
[self.cell.lengthField addTarget:self action:@selector(lengthEdited:) forControlEvents:UIControlEventEditingChanged];
return self.cell;
}
- (void)lengthEdited:(id)sender{
CGPoint position = [sender convertPoint:CGPointZero toView:self.quantityTableView];
NSIndexPath *indexPath = [self.quantityTableView indexPathForRowAtPoint:position];
[questionnaire setActiveItem: indexPath.row];
[[questionnaire.itemsArray objectAtIndex:activeItem]setItemLength self.cell.lengthField.text];
}
For simplicity's sake, the dimensions can be stored as strings. Now, I'm adding instances of item at runtime, and I'm trying to edited the dimensions of those instances shortly thereafter, but when I try to do that, only the last object in the tableView seems to respond properly. I've NSLog'd the activeItem, and I see that, whenever I edit a cell, it's setting activeItem to the value of indexPath.row, which is absolutely correct. However, when I also try to NSLog the value of itemLength in the activeItem, I get null values returned until I attempt to log the final item in array. Once I do that, regardless of which cell I edit, I get the value of the last item in that array's length.
Does anybody have an idea of what I'm doing wrong here? I'm hopelessly stuck. Thank you in advance.