내 앱이 질문을하고 질문에 따라 UITextField 또는 UISwitch를 배치합니다.Objective-C : UItextFields를 스크롤 오프 할 때 입력을 유지하고 태그 이름을 유지하는 방법은 무엇입니까?
사용자가 텍스트를 입력하면 자동으로 어떤 textField를 감지하고 그에 따라 텍스트를 배치합니다.
잘 작동하지만 항목을 스크롤 오프하면 사용자 입력과 태그 이름도 제거되며 그 위에 새로운 항목을 배치하는 영역이 표시됩니다.
그래서 사용자가 텍스트를 입력하면 이전 textField에 텍스트가 저장됩니다.
이 문제를 방지하는 방법을 알고 싶습니다.
의견이 있습니까? 미리 감사드립니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
NSLog(@"-------------cellForRowAtIndexPath---------------");
cell_id = [qid objectAtIndex:[indexPath row] ];
static NSString *CellIdentifier = @"Cell";
label = nil;
cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[self configureLabel];
[[cell contentView] addSubview:label];
}
dict = [qtext objectAtIndex:[indexPath row]];
celltext = [NSString stringWithFormat:@"%@\n\n\n",[[dict allKeys] objectAtIndex:0]];
dict = [qtype objectAtIndex:[indexPath row]];
type = [[dict allKeys] objectAtIndex:0];
//place the question
cell.textLabel.text = celltext;
NSLog(@"celltext=%@",celltext);
if([type isEqualToString:@"devider"]){
[self configureDevider];
}else{
[self configureCell];
}
if([cell_id intValue] == ([qid count])){
tabledone = @"Yes";
}
tableView.backgroundColor=[UIColor clearColor];
tableView.opaque=NO;
tableView.backgroundView=nil;
NSString *a = [arrAllheight objectAtIndex:[indexPath row]];
allheight +=thisheight;
thisheight =[a intValue];
if([type isEqualToString:@"YN"]){
DCRoundSwitch *ynSwitch = [[DCRoundSwitch alloc] initWithFrame:CGRectMake(220,thisheight-40,80,27)] ;
[email protected]"Yes";
[email protected]"No";
[answers addObject:ynSwitch];
[cell addSubview:ynSwitch];
[ynSwitch setTag:[cell_id intValue]];
[ynSwitch addTarget:self action:@selector(setAnswersForRoundSwitches:) forControlEvents:UIControlEventValueChanged];
i++;
}else if([type isEqualToString:@"freetext"]){
//When the done button was clicked, remove the keybords from the screen
[self makeTextField];
[rtxtfield addTarget:self action:@selector(setAnswersfortextFields:) forControlEvents:UIControlEventEditingDidEndOnExit];
// [rtxtfield value];
}else if([type isEqualToString:@"dropdown"]){
picc = [picker_array objectForKey:[[NSString alloc] initWithFormat:@"%d",cell_id]];
//Choose an array for this textField
// [self getPickerArray];
[self makeTextField];
//[rtxtfield addTarget:self action:@selector(setAnswersfortextFields:) forControlEvents:UIControlEventEditingDidEndOnExit];
//When the done button was clicked, remove the keybords from the screen
[rtxtfield addTarget:self action:@selector(textFieldReturn:) forControlEvents:UIControlEventEditingDidEndOnExit];
//Get the tag for picker
[rtxtfield addTarget:self action:@selector(getTag:) forControlEvents:UIControlEventTouchDown];
//Display picker
[rtxtfield addTarget:self action:@selector(acsheet:) forControlEvents:UIControlEventTouchDown];
//set Tag for the textField
[rtxtfield setTag:[cell_id intValue]];
NSLog(@"rtxtfield tag=%d",rtxtfield.tag);
}
if([type isEqualToString:@"devider"]){
[self caliculateHeightofCell];
}else{
[self caliculateHeightofCell];
}
return cell;
}
uitableview를 사용하고 있습니까? – Radu
예, 있습니다. 나는 그것을 언급하지 않아서 미안합니다. – user973067
글쎄 문제는 셀 whit있을 수 있습니다. cellForRowAtIndexPath있는 if (cell == nil) {} 약간의 테스트를 수행하고 // if (cell == nil) {colom //} 그리고 그것이 작동하는지 확인하십시오. – Radu