繁体   English   中英

带有嵌入的UITextFields的UITableView,使用页脚节进行验证,是否更新页脚问题?

[英]UITableView with embeded UITextFields, using section footer for validation, update footer issues?

我正在使用的UITableView每行上都有两个UITextFields ,以设置密码和确认密码。

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

我正在使用..

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

为了刷新页脚文本以及我在其他地方设置的NSString。

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

我以为if (cell == nil)是否可以阻止重新绘制单元格,但显然不会。

我在这里做错了什么?

创建一个变量来存储文本,并且可以在对象内访问它。 将此添加到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";

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM