2013-03-05 23 views
0

我正在使用UITableView,每行上有兩個UITextFields,以設置密碼和確認密碼。UITableView與嵌入的UITextFields,使用節頁腳進行驗證,更新頁腳問題?

我想使用的頁腳節顯示,如果通行碼匹配,或者過短等

我使用..

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

要刷新頁腳文本,以及我在其他地方設置的NSString。

然而,當我打電話reloadSections它迫使UITextFields重新cellForRowAtIndexPath - 增加。

我以爲if (cell == nil)會阻止細胞重繪,但顯然不是。

我在這裏做錯了什麼?

回答

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"; 
0

您可以將這些textField添加爲全局變量並創建一次,然後將它們傳遞給cellForRowAtIndexPath。他們將被添加以前的狀態