我有一個分組的靜態UITableViewController,每節有3行。每行包含一個UITextField。我如何獲得每個UITextField的值?從幾個UITextFields獲取值
到目前爲止,我所看到的是如何獲得一個UITextField的值。如果我必須得到一個以上,我應該怎麼做。
我打算把這些字段的值放在一個NSMutableDictionary中。
這是我的用於製備表視圖代碼:(不相關部分被省略)
#import "AddItemTableViewController.h"
#import "iMonggoFetcher.h"
@interface AddItemTableViewController() <UITextFieldDelegate>
@property (weak, nonatomic) NSMutableDictionary *productItem;
//required
@property (weak, nonatomic) IBOutlet UITextField *stockNoTextField;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *retailPriceTextField;
//basic info
@property (weak, nonatomic) IBOutlet UITextField *costTextField;
@property (weak, nonatomic) IBOutlet UITextField *descriptionTextField;
@property (weak, nonatomic) IBOutlet UITextField *barcodesTextField;
@property (weak, nonatomic) IBOutlet UITextField *tagsTextField;
@property (weak, nonatomic) IBOutlet UISwitch *exemptFromTaxSwitch;
//advanced features
@property (weak, nonatomic) IBOutlet UISwitch *allowDecimalQuantitiesSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *enableOpenPriceSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *disableDiscountSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *disableInventorySwitch;
@end
@implementation AddItemTableViewController
@synthesize productItem = _productItem;
@synthesize stockNoTextField = _stockNoTextField;
@synthesize nameTextField = _nameTextField;
@synthesize retailPriceTextField = _retailPriceTextField;
@synthesize costTextField = _costTextField;
@synthesize descriptionTextField = _descriptionTextField;
@synthesize barcodesTextField = _barcodesTextField;
@synthesize tagsTextField = _tagsTextField;
@synthesize exemptFromTaxSwitch = _exemptFromTaxSwitch;
@synthesize allowDecimalQuantitiesSwitch = _allowDecimalQuantitiesSwitch;
@synthesize enableOpenPriceSwitch = _enableOpenPriceSwitch;
@synthesize disableDiscountSwitch = _disableDiscountSwitch;
@synthesize disableInventorySwitch = _disableInventorySwitch;
- (IBAction)save:(UIBarButtonItem *)sender {
[self.productItem setValue:self.stockNoTextField.text forKey:IMONGGO_PRODUCT_STOCK_NO];
[self.productItem setValue:self.nameTextField.text forKey:IMONGGO_PRODUCT_NAME];
[self.productItem setValue:self.retailPriceTextField.text forKey:IMONGGO_PRODUCT_RETAIL_PRICE];
}
#pragma mark - UITextField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// optionally trigger delegate method here
}
#pragma mark - View lifecycle
- (void) viewWillAppear:(BOOL)animated{
//[self.stockNoTextField becomeFirstResponder];
}
- (void) viewDidLoad{
[super viewDidLoad];
self.stockNoTextField.delegate = self;
self.nameTextField.delegate = self;
self.retailPriceTextField.delegate = self;
//will do the rest later, just trying it out for now
}
@end
向我們展示您的代碼,用於製作UITableViewCell .. – 2012-02-06 06:17:01
請參閱上面的@AdilSoomro編輯。 – acecapades 2012-02-06 06:29:30
告訴我們您的cellForRowAtIndexPath代碼: – Ankur 2012-02-06 10:43:59