iphone - IOS:清除模态视图 Controller 中的先前内容

标签 iphone ios objective-c uitableview modalviewcontroller

在我的应用程序中,我使用了一个模态视图 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/

相关文章:

iphone - 在 iphone app/ios 中,如何制作覆盖导航栏和键盘的透明 'loading' 覆盖层?

iphone - 我可以更改可供销售的应用程序购买价格吗?不用再进入审核?

objective-c - 如何通过 NSJSONSerialization 在 JSON 中包含 null 值?

iphone - 设置 UITableView contentInset 也会插入部分标题 View

objective-c - PDFPage 子类上没有调用 init 吗?

iphone - 如何从类别中的重载函数调用原始函数?

ios - 使用 Xcode for ios 进行自动化测试

ios - 如何将 Apple 的 iAds 添加到我基于 OpenGL 的 iPhone 应用程序?

ios - 在随机颜色数组中替换属性 CGColorGetComponents(在 swift 4 中不可用)

iphone - 动态改变原型(prototype)单元的高度