【问题标题】:get tableView of a UISearchBar获取 UISearchBar 的 tableView
【发布时间】:2023-03-03 19:10:01
【问题描述】:

我的 TVC 顶部有一个 UISearchBar。如果搜索处于活动状态,它会在普通 tableView 顶部显示另一个 tableView(这是正常的)。现在我需要在 prepareForSegue() 中获取“searchTableView”,因为我需要调用:

var newIndexPath = table.indexPathForSelectedRow!

如果您搜索某些内容,则会失败。 我也无法在 didSelectRowAtIndexPath() 中做出决定,因为 segue 被调用得很快,因为它直接“链接”到 UITableViewCell。我也尝试从 ViewController 创建转场,但这也失败了,因为转场需要再次在同一个 ViewController 上结束。

所以基本上我想问是否有人知道如何解决上面代码行中的错误将进行搜索。

【问题讨论】:

    标签: ios iphone swift uitableview uisearchbar


    【解决方案1】:
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    {
        NSIndexPath *indexPath;
        if (self.searchDisplayController.active) 
        {
            indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
        } 
        else 
        {
            indexPath = [self.tableView indexPathForSelectedRow];
        }
    
        // Use the indexPath...
    }
    

    【讨论】:

    • 它不起作用,因为 searchDisplayController 在 iOS 8.0 中已被弃用
    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多