簡體   English   中英

無需重新加載即可更新 UITableView 中的節頁腳標題

[英]Update section footer title in UITableView without reloading

當我通過鍵盤輸入文本時,我希望能夠以編程方式更新表視圖中某個部分的頁腳標題。 當我單擊一個單元格以使其 detailText 視圖可編輯時,鍵盤會出現,因此我想更新頁腳標題而不從數據源重新加載。

事實上,如果我這樣做,鍵盤就會消失,所以這不是一種很好的交互形式。 我一直無法找到解決這個問題的好方法……有什么建議嗎?

謝謝

我知道我遲到了這個話題,但我發現你可以簡單地做到這一點:

[self.tableView beginUpdates];
[self.tableView footerViewForSection:section].textLabel.text = @"Whatever";
[[self.tableView footerViewForSection:section].textLabel sizeToFit];
[self.tableView endUpdates];

如果你有分組表,你可以使用:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 17)]; //I'm not sure about the frame...
    yourLabel.font = [UIFont systemFontOfSize:16];
    yourLabel.shadowColor = [UIColor whiteColor];
    yourLabel.shadowOffset = CGSizeMake(0, 1);
    yourLabel.textAlignment = UITextAlignmentCenter;
    yourLabel.textColor = RGB(76, 86, 108);
    yourLabel.backgroundColor = [UIColor clearColor];
    yourLabel.opaque = NO;
    return yourLabel;
}

.h文件中聲明yourLabel 然后,您可以通過

yourLabel.text = @"whatever you want";

請檢查是否有效:)

第一部分 (ziro)

[self.tableView footerViewForSection:0].textLabel.text = @"test";

Mark Alldritt 的回答很好,但有時標簽大小不正確。 固定示例如下(對於部分 == 0):

[self.tableView beginUpdates];
UILabel *footerLabel = [self.tableView footerViewForSection:0].textLabel;

footerLabel.text = [self tableView:self.tableView titleForFooterInSection:0];
CGRect footerLabelFrame = footerLabel.frame;
footerLabelFrame.size.width = self.tableView.bounds.size.width;
footerLabel.frame = footerLabelFrame;
[self.tableView endUpdates];

斯威夫特 5 個回答

tableView.beginUpdates()

tableView.footerView(forSection: 0)?.textLabel?.text = "Text Here"

tableView.endUpdates()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM