我有一个实现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;
}
}