0
我的兩個文本框在我的.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";
ATTEMPTS TO DEBUG:
當我嘗試使用此代碼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);
我得到兩個空值!
這就像我對文本字段的更改根本沒有被跟蹤!
每次在表視圖上重新加載一行時,您也會創建新的文本字段。或請求任何特定單元格上的文本字段。 – Wain
你在哪裏設置標籤的文本字段? –
我在cellForRowAtIndexPath中設置標籤 – AllieCat