在我的应用程序中,我使用了一个模态视图 Controller ,它包含一个带有多个文本字段的 TableView。
假设我的主视图 Controller 名为 SridharViewController,模态视图 Controller 名为 ResultsViewController
SridharViewController 中有一个按钮,触摸该按钮将打开模态(ResultsViewController)
[self presentModalViewController:resultsViewController animated:YES];
在结果 View Controller 中,有许多在 TableView 中对齐的文本字段。和一个“确定”按钮。按“确定”按钮将关闭模态
[self dismissModalViewControllerAnimated:YES];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath called");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//UITextField *formTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 11, 270, 30)];
UITextField *formTextField =nil;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if(indexPath.row == 0){
formTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 12, 270, 30)];
}
else{
formTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 11, 270, 30)];
}
}else{
if(indexPath.row == 0){
formTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 12, 670, 30)];
}
else{
formTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 11, 670, 30)];
}
}
formTextField.placeholder = [self.formFields objectAtIndex:indexPath.row];
formTextField.tag = indexPath.row;
formTextField.text=@"";
formTextField.adjustsFontSizeToFitWidth = YES;
formTextField.textColor = [UIColor blackColor];
formTextField.borderStyle = UITextBorderStyleNone;
formTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
[formTextField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[formTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
formTextField.backgroundColor = [UIColor clearColor];
formTextField.textAlignment = UITextAlignmentLeft;
formTextField.delegate = self;
[formTextField setEnabled: YES];
[formTextField setReturnKeyType:UIReturnKeyNext];
[self.textFields addObject:formTextField];
[cell addSubview:formTextField];
return cell;
}
当我第二次调用模态视图时,模态显示之前的内容。我想清除以前的内容。
我已经尝试了更新和重新加载功能。它们都没有调用 cellForRowAtIndexPath
方法。
[self.theTable reloadInputViews];
请提供最好的方法。
最佳答案
在 viewWillAppear
中执行以下操作
arrayOfInputs = [NSArray array];
[self.tableview reloadData];
arrayOfInputs
是您存储将显示在 tableview 上的对象的位置。将数据源清空并重新加载 TableView 后,所有内容将被清除。然后您可以使用所需数据重新加载 TableView 。
关于iphone - IOS:清除模态视图 Controller 中的先前内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17584932/