我有一個實現UISearchBarDelegate的UITableView。我在self.searchDisplayController.searchResultsTableView中有兩個部分,並希望用返回的結果數來更新這些UILabel。做這個的最好方式是什麼?執行搜索後更新節頭值
我正在使用CoreData。
THX
我有一個實現UISearchBarDelegate的UITableView。我在self.searchDisplayController.searchResultsTableView中有兩個部分,並希望用返回的結果數來更新這些UILabel。做這個的最好方式是什麼?執行搜索後更新節頭值
我正在使用CoreData。
THX
你需要處理適當的值,抓住你UITableView
數據源法- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
。然後,一旦你獲得了新的值(並填充你將要在該方法中使用的任何源),只需撥打[myTableView reloadData]
即可。
因此,假設您將標題標題存儲在名爲HeaderTitles
的數組中。 (這是假設你已經得到了已填充了您的節標題標題一個NSMutableArray/NSArray的)
// This is a method I made up, which is where you get the data returned...
- (void)gotNewTitle:(NSString *)title forSection:(NSUInteger)section {
[[self HeaderTitles] replaceObjectAtIndex:section withObject:title];
[[self myTableView] reloadData];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[self HeaderTitles] objectAtIndex:section];
}
如果你不想使用一個NSArray,因爲你有2個部分是肯定的,您可以使用以下方法(假定2個屬性,NSString
,FirstSectionTitle
和SecondSectionTitle
):
- (void)gotNewTitle:(NSString *)title forSection:(NSUInteger)section {
switch (section) {
case 0:
[self setFirstSectionTitle:title];
break;
case 1:
[self setSecondSectionTitle:title];
break;
default:
break;
}
[[self myTableView] reloadData];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return [self FirstSectionTitle];
break;
case 1:
return [self SecondSectionTitle];
break;
default:
return @"";
break;
}
}