2011-05-08 39 views
6

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

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

謝謝

回答

6

如果你已經細分電子郵件的表,你可以使用:

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

訪問,請檢查其是否正常工作:)

+1

是的,它可能會工作。但是我將不得不處理大量的團體,所以對我來說處理所有不同的標籤並不那麼容易。我真的會試圖以一種乾淨的方式去做... – marzapower 2011-05-08 19:25:05

+0

順便說一下,我應該在'yourFrame' CGRect實例中放入什麼尺寸? – marzapower 2011-05-08 19:25:35

+0

您可以在'NSArray'中放置標籤,然後使用'for'循環。 – akashivskyy 2011-05-08 19:26:21

6

我知道我遲到了這個線程,但我發現,你可以簡單地這樣做:

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

對於第一部分(齊羅)

[self.tableView footerViewForSection:0] = .textLabel.text @ 「測試」;

1

馬克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]; 
相關問題