我在textFieldDidEndEditing上插入文本字段数据到数组中。如何替换NSARRAY中值和键相等的数据?
但我不想重复。如果用户更改了文本字段数据,我希望它被替换为新的并更新了字典中的名称为“product”的值为“bagel”的名称。
.H
@interface Bread_TableViewController : UITableViewController <UITextFieldDelegate>
{
NSMutableArray *productarray;
}
.M
- (void)viewDidLoad {
[super viewDidLoad];
productarray = [NSMutableArray array];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
// Make sure to set the label to have a ta
NSString*textfieldclicked;
if (textField.tag == 1) {
[email protected]"Unit";
} else if (textField.tag ==2) {
[email protected]"Case";
}
id textFieldSuper = textField;
while (![textFieldSuper isKindOfClass:[UITableViewCell class]]) {
textFieldSuper = [textFieldSuper superview];
}
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)textFieldSuper];
InventoryTableViewCell *cell = (InventoryTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:textField.text,textfieldclicked,cell.product.text,@"product",nil];
[productarray addObject:plainPart];
}
由于未捕获的异常“NSRangeException”而终止应用,原因:'*** - [__ NSArrayM replaceObjectAtIndex:withObject:]:index 2147483647超出空数组的边界' – ASH