情况:
我的两个文本字段在我的 .h 文件中声明:
@interface DetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate, UITextFieldDelegate> {
UITextField *countTotalFieldUniversal;
UITextField *flavorNameUniversal;
}
并在我的 .m 文件中实例化:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
// Label default cell
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
//Text fields used for editing
countTotalFieldUniversal = [[UITextField alloc] initWithFrame:CGRectMake(200, 10, 85, 30)];
countTotalFieldUniversal. delegate = self;
flavorNameUniversal = [[UITextField alloc] initWithFrame:CGRectMake(10, 8, 280, 30)];
flavorNameUniversal.delegate = self;
flavorNameUniversal.text = @"Flavor";
countTotalFieldUniversal.text = @"Count";
调试尝试:
当我尝试使用此代码在 setEditing 中打印当前文本字段值时:
NSString *flavorText = ((UITextField*)[self.view viewWithTag:1]).text;
NSString *countText = ((UITextField*)[self.view viewWithTag:2]).text;
NSLog(@"newFlavorName: %@", flavorText);
NSLog(@"newCountTotal: %@", countText);
我只得到未经编辑的原始标签:“风味”和“计数”。
当我尝试使用此代码在 setEditing 中打印当前文本字段值时:
NSString * newFlavorName = flavorNameUniversal.text;
NSString * newCountTotal = countTotalFieldUniversal.text;
NSLog(@"newFlavorName: %@", newFlavorName);
NSLog(@"newCountTotal: %@", newCountTotal);
我得到两个空值!
就好像我对文本字段的更改根本没有被跟踪!