2

だから私は検索バーを iOS7 の tableview の Nav バーと結合しようとしていました。

私は電話 self.searchDisplayController.displaysSearchBarInNavigationBar = YES;しましたそしてそれはうまく見えます。

ただし、テーブルビューの任意の場所をタップすると、検索バーがアクティブになります。基本的に、表のセルを定期的にクリックする方法はありません。

私はここで正確に何を逃したのだろうか?

参考までに、テーブルビューに関連するコードは次のようになります: (ストーリーボードを使用してクリックロジックを処理しました)

    #pragma mark - Table view delegate method

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex:section];
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return 1;
    } else {
        return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] count];;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [searchResults count];
    } else {
        return [self.contacts[section] count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"contactCell";
    UITableViewCell *cell;
    Contact *contact;

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        contact = searchResults[indexPath.row];
    } else {
        cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
        contact = [[self.contacts objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    }

    UILabel *nameLabel = (UILabel *)[cell viewWithTag:7];
    UIImageView *starMark = (UIImageView *)[cell viewWithTag:9];

    NSString *nameString = [NSString stringWithFormat:@"%@ %@",contact.firstName, contact.lastName];

    if ([contact.star isEqual:@0]) {
        starMark.hidden = YES;
    } else {
        starMark.hidden = NO;
    }

    [nameLabel setText:nameString];

    return cell;
}

また、セグエ メソッドは次のように定義されています。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"pushContactDetail"]) {
        NSIndexPath *indexPath;
        Contact *contact;
        if (self.searchDisplayController.active == YES) {
            indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
            contact = searchResults[indexPath.row];
        } else {
            indexPath = [self.tableView indexPathForSelectedRow];
            contact = [[self.contacts objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        }
        //get indexPath from selected sushi

        //initialize the detail view controller and push it
        CIContactViewController *destViewController = segue.destinationViewController;
        destViewController.contact = contact;
    }
}
4

0 に答える 0