【问题标题】:UITableView with embeded UITextFields, using section footer for validation, update footer issues?带有嵌入 UITextFields 的 UITableView,使用节页脚进行验证,更新页脚问题?
【发布时间】:2013-03-05 09:09:24
【问题描述】:

我使用UITableView,每行有两个UITextFields,设置密码和确认密码。

我想使用部分页脚来显示密码是否匹配或是否太短等。

我正在使用..

[[self passcodeTableView]reloadSections:[NSIndexSet indexSetWithIndex:0] 
                withRowAnimation:UITableViewRowAnimationFade];

刷新页脚文本,以及我在别处设置的 NSString。

但是,当我调用 reloadSections 时,它会强制将 UITextFields 重新添加到 cellForRowAtIndexPath

我认为if (cell == nil) 会阻止重绘单元格,但显然不会。

我在这里做错了什么?

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    创建一个变量来存储文本并在您的对象中访问。将此添加到 YourClass.m:

    @interface YourClass () {   
         UILabel *footerLabel;
    }
    
    @end
    

    将此方法添加到您的类中:

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {
        if (!footerLabel) {
            footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0)];
        }
    
        return footerLabel;
    }
    
    - (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
        return 60.0;
    }
    

    然后,当你想改变文字时,只需更新footerLabel:

    footerLabel.text = @"Your new text";
    

    【讨论】:

      【解决方案2】:

      您可以将这些文本字段添加为全局变量并创建一次,然后将它们传递给cellForRowAtIndexPath。它们将被添加到之前的状态

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-21
        • 2011-02-12
        • 1970-01-01
        • 2011-06-08
        • 1970-01-01
        • 2021-10-17
        相关资源
        最近更新 更多