1
我創建UITableView並向單元格的內容添加文本框以允許用戶輸入他的數據,並且當用戶結束編輯文本字段時我想將插入數據保存爲文本字段,但問題是UITextField
檢索爲空。在表視圖中從UItextField中檢索插入用戶數據
在cellForRowAtIndexPath
我加入
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
TextField1 = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 80,45)];
TextField2 = [[UITextField alloc] initWithFrame:CGRectMake(83, 0, 70,45)];
TextField3 = [[UITextField alloc] initWithFrame:CGRectMake(156, 0, 70,45)];
[TextField1 setDelegate:self];
[TextField2 setDelegate:self];
[TextField3 setDelegate:self];
TextField1.userInteractionEnabled=YES;
TextField1.enabled=YES;
TextField2.userInteractionEnabled=YES;
TextField2.enabled=YES;
TextField3.userInteractionEnabled=YES;
TextField3.enabled=YES;
[cell.contentView addSubview:TextField1];
[cell.contentView addSubview:TextField2];
[cell.contentView addSubview:TextField3];
return cell;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSString*VisitDateStr=[NSString stringWithFormat:@"%@",TextField1.text];
NSLog(@"%@",VisitDateStr);
}
結果(空)。 我如何檢索在tableview上插入文本字段的用戶詳細信息?
謝謝,我感謝任何幫助。
謝謝Samkit耆那教的,我檢索空。 –
你是否獲得textField也爲零? –
是它的null我打印結果使用NSLog(@「%@」,TextField1.text); 結果(null) –