搜索后选择单元格不会在视觉上偏离,但会加载下一个视图Swift Xcode

时间:2016-03-03 04:31:34

标签: ios xcode swift uitableview

我有一个TableView,基本上用户可以从名单列表中搜索。我有搜索设置,所以他们可以输入一个名字,然后搜索那个人。

当他们选择一个单元格时,它所做的只是将名称字符串传递给下一个视图。当没有人搜索时它完全正常,你只需在表格中选择一个单元格。但是,当您搜索名称,然后选择时,您点击该单元格,它将变为灰色。然后它加载下一个显示,但不显示它。然后,当我点按搜索栏上的“取消”时,它会崩溃该应用。我不知道该怎么做/这个错误是什么。

var appleProducts = ["I am using a custom name"]
var filteredAppleProducts = [String]()
var resultSearchController = UISearchController()

 override func viewDidLoad() {

    super.viewDidLoad()

    self.loadNames()

    self.resultSearchController = UISearchController(searchResultsController: nil)
    self.resultSearchController.searchResultsUpdater = self
    self.resultSearchController.dimsBackgroundDuringPresentation = false
    self.resultSearchController.searchBar.sizeToFit()
    self.resultSearchController.searchBar.placeholder = "Type Name Here"
    self.tableView.tableHeaderView = self.resultSearchController.searchBar   
    self.tableView.reloadData() 
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if (self.resultSearchController.active)
    {
        return self.filteredAppleProducts.count
    }
    else
    {
        return self.appleProducts.count
    }
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! AddSearchTableViewCell

    if (self.resultSearchController.active)
    {
        cell.name.text = self.filteredAppleProducts[indexPath.row]
        return cell
    }
    else
    {
        cell.name.text = self.appleProducts[indexPath.row]
        return cell
    }
}

func updateSearchResultsForSearchController(searchController: UISearchController)
{
    self.filteredAppleProducts.removeAll(keepCapacity: false) 
    let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text!)
    let array = (self.appleProducts as NSArray).filteredArrayUsingPredicate(searchPredicate)
    self.filteredAppleProducts = array as! [String] 
    self.tableView.reloadData()
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    //

    let indexPath = tableView.indexPathForSelectedRow 
    let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! AddSearchTableViewCell   
    print("Going to Did Select Name!")
    self.performSegueWithIdentifier("didSelectName", sender: currentCell.name.text)

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "didSelectName" {

        let completeSignUpVC = segue.destinationViewController as! AddUpViewController
        let selectedRowIndex = self.tableView.indexPathForSelectedRow
        let currentCell = tableView.cellForRowAtIndexPath(selectedRowIndex!) as! AddSearchTableViewCell
        completeSignUpVC.userObjectId = currentCell.name.text
    }

}

提前感谢您的任何建议。

错误:

[_UIFullscreenPresentationController adaptivePresentationController]: unrecognized selector sent to instance 0x7f890abe6cf0

2016-03-02 23:57:39.775 XX 2 [3282:82749] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [_ UIFullscreenPresentationController adaptivePresentationController]:无法识别的选择器发送到实例0x7f890abe6cf0' * 第一次抛出调用堆栈: (     0 CoreFoundation 0x000000010e1cff65 exceptionPreprocess + 165     1 libobjc.A.dylib 0x000000010d8c1deb objc_exception_throw + 48     2 CoreFoundation 0x000000010e1d858d - [NSObject(NSObject)doesNotRecognizeSelector:] + 205     3 CoreFoundation 0x000000010e125f7a ___转发_ + 970     4 CoreFoundation 0x000000010e125b28 _CF_forwarding_prep_0 + 120     5 UIKit 0x000000010f3e7389 - [UISearchController _searchPresentationController] + 134     6 UIKit 0x000000010efc3755 - [_ UISearchControllerTransplantSearchBarAnimator animateTransition:] + 215     7 UIKit 0x000000010eb6dede 56- [UIPresentationController runTransitionForCurrentState] _block_invoke + 2638     8 UIKit 0x000000010ea1a4be _runAfterCACommitDeferredBlocks + 317     9 UIKit 0x000000010ea2c7ee _cleanUpAfterCAFlushAndRunDeferredBlocks + 95     10 UIKit 0x000000010ea384e6 _afterCACommitHandler + 90     11 CoreFoundation 0x000000010e0fb9d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23     12 CoreFoundation 0x000000010e0fb947 __CFRunLoopDoObservers + 391     13 CoreFoundation 0x000000010e0f159b __CFRunLoopRun + 1147     14 CoreFoundation 0x000000010e0f0e98 CFRunLoopRunSpecific + 488     15 GraphicsServices 0x0000000110d54ad2 GSEventRunModal + 161     16 UIKit 0x000000010ea0e676 UIApplicationMain + 171     17 XX 0x000000010bccac4d main + 109     18 libdyld.dylib 0x00000001141ba92d start + 1     19 ??? 0x0000000000000001 0x0 + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止 (lldb)

0 个答案:

没有答案