[英]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.