簡體   English   中英

在表格視圖中點擊單元格不會執行任何操作

[英]Tapping cell in table view does not do anything

我在應用程序的其中一個表視圖中選擇時遇到問題。 基本上,問題是我只能通過點擊作為搜索結果的單元格來選擇另一個視圖控制器。 由於某種原因,我無法在標准表格視圖中點擊單元格。

當我正常點擊一個單元格時,什么也沒發生。 但是,如果我使用搜索欄搜索單元格,則可以點擊單元格,它們將按預期順序鎖定到另一個視圖控制器。 我不知道為什么。

這是我的代碼:

override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.

    if tableView == self.searchDisplayController?.searchResultsTableView {
        return searchResults.count
    } else {
    if names.count == 0 {
        if enterButtonTapped == false {
            backgroundLabel.text = "Before you add any transactions, you must first set a budget. You can do this by tapping the 'Budget' tab."
        } else {
            backgroundLabel.text = "You haven't added any transactions yet. Tap the add button to add a new transaction."
        }
        backgroundLabel.frame = CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height)
        backgroundLabel.numberOfLines = 0
        backgroundLabel.textAlignment = NSTextAlignment.Center
        backgroundLabel.sizeToFit()
        backgroundLabel.hidden = false
        backgroundLabel.textColor = UIColor.lightGrayColor()
        clearButton.enabled = false

        self.tableView.backgroundView = backgroundLabel
        self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
        self.tableView.scrollEnabled = false
        return 0
    } else {
        backgroundLabel.hidden = true
        self.tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
        self.tableView.scrollEnabled = true
        clearButton.enabled = true
        return names.count
    }
    }
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell:CustomTransactionTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomTransactionTableViewCell
    cell.selectionStyle = UITableViewCellSelectionStyle.None

    if tableView == self.searchDisplayController?.searchResultsTableView {
        cell.paymentNameLabel.text = (searchResults.objectAtIndex(indexPath.row)) as? String
        //println(searchResults.objectAtIndex(indexPath.row))
        var indexValue = names.indexOfObject(searchResults.objectAtIndex(indexPath.row))
        cell.costLabel.text = (values.objectAtIndex(indexValue)) as? String
        cell.dateLabel.text = (dates.objectAtIndex(indexValue)) as? String

        if images.objectAtIndex(indexValue) as NSObject == 0 {
            cell.paymentArrowImage.hidden = false
            cell.creditArrowImage.hidden = true
        } else if images.objectAtIndex(indexValue) as NSObject == 1 {
            cell.creditArrowImage.hidden = false
            cell.paymentArrowImage.hidden = true
        }
        //This works, unless there are two payments with the same name. To revert to previous version, remove tableView if statement and just keep code below the else.
    } else {
        cell.paymentNameLabel.text = (names.objectAtIndex(indexPath.row)) as? String
        cell.costLabel.text = (values.objectAtIndex(indexPath.row)) as? String
        cell.dateLabel.text = (dates.objectAtIndex(indexPath.row)) as? String

        if images.objectAtIndex(indexPath.row) as NSObject == 0 {
            cell.paymentArrowImage.hidden = false
            cell.creditArrowImage.hidden = true
        } else if images.objectAtIndex(indexPath.row) as NSObject == 1 {
            cell.creditArrowImage.hidden = false
            cell.paymentArrowImage.hidden = true
        }
    }
    return cell
}

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    if tableView == self.searchDisplayController?.searchResultsTableView {
        return false
    } else {
        return true
    }
}

視圖控制器通過推送選擇連接到情節提要中的單元。

最初我想知道是否是這一行(但不是):

cell.selectionStyle = UITableViewCellSelectionStyle.None

有任何想法嗎?

這個問題實際上很簡單。 我只需要將表視圖屬性內的“選擇”設置從“無選擇”更改為“單選”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM