2012-05-06 3 views
0

UISearchBarDelegateを実装するUITableViewがあります。 self.searchDisplayController.searchResultsTableViewに2つのセクションがあり、返された結果の数でUILabelを更新したいと考えています。これを行う最善の方法は何ですか?検索後にセクションヘッダーの値を更新します。

私はCoreDataを使用しています。あなたのUITableViewデータソース方式- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sectionに適切な値を引くに対処する必要があります

THX

答えて

0

。次に、新しい値を取得したら(そのメソッドで使用するソースを入力したら)、単に[myTableView reloadData]を呼び出します。

だから、ヘッダタイトルをHeaderTitlesという配列に格納しているとします。あなたは確かに2つのセクションを持っているので、あなたではなく、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]; 
} 

を(これは、すでにあなたのセクションヘッダのタイトルが移入されたNSMutableArrayの/ NSArrayのを持っていると仮定し)

- (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; 
    } 
} 
:あなたは(2つの特性を前提とし、両方の NSStringFirstSectionTitleSecondSectionTitle)は、以下の方法を使用することができます
関連する問題