一旦用戶完成在UITextfield中輸入文本,我會先將數據放入字典中,然後將字典添加到數組中。但對於插入陣列後,由於某種原因。它記錄爲空..如何將字段數據保存在字典中,然後保存在數組中?
.H
@interface Bread_TableViewController : UITableViewController <UITextFieldDelegate>
{
NSMutableArray * inventoryarray;
}
**.m**
- (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];
NSMutableDictionary * productinfo = [[NSMutableDictionary alloc] init];
[productinfo setObject:cell.product.text forKey:@"product"];
[productinfo setObject:textField.text forKey:textfieldclicked];
NSLog(@"productin %@", productinfo);
[inventoryarray addObject: productinfo];
}
-(IBAction)save{
NSLog(@"array %@", inventoryarray);
}
豬頭,ALLOC UR-INIT? –
只是固定的....但是我的數組一次只顯示一個字典..:/ – ASH
請看看我的回答 –