小编Bra*_*ney的帖子

搜索TableView无法选择行

在搜索tableView时,每次我尝试选择一行时,它都会将我带回到未搜索的tableView.我错过了什么?当不通过表过滤时,segue完美地工作.激活searchBar时,选择行的能力会消失.

import UIKit
import Foundation

class BenchmarkWODViewController: UITableViewController, UISearchResultsUpdating {

    var WodList = [WOD]()
    var FilteredWodList = [WOD]()
    var Keyword = ""
    var searchController : UISearchController?
    var index = Int()

    @IBAction func backButton(sender: AnyObject) {
        self.navigationController?.popViewControllerAnimated(true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        for wodData in BenchmarkWODs.library {
            let wod = WOD(dictionary: wodData)
            WodList.append(wod)
    }

    // Search Bar
        self.searchController = UISearchController(searchResultsController: nil)
        self.searchController?.searchBar.autocapitalizationType = .None
        self.tableView.tableHeaderView = self.searchController?.searchBar
        self.searchController?.searchResultsUpdater = self
        self.Keyword = ""
        definesPresentationContext = true

        self.filterByName()
    }


    func filterByName(){ …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift swift2

4
推荐指数
1
解决办法
1032
查看次数

字典中的值之和 - Swift

所以这只是下面的一些类似示例代码.我试图把所有人的高度都加在一起,这样我就能得到一个平均值.我似乎无法弄清楚如何使用一系列字典来完成此操作.我也在使用Xcode 3.

let people = [
    [
    "name": "John Doe",
    "sex": "Male",
    "height": "183.0"
    ],
    [
    "name": "Jane Doe",
    "sex": "Female",
    "height": "162.0"
    ],
    [
    "name": "Joe Doe",
    "sex": "Male",
    "height": "179.0"
    ],
    [
    "name": "Jill Doe",
    "sex": "Female",
    "height": "167.0"
    ],
]
Run Code Online (Sandbox Code Playgroud)

下面的代码似乎只是创建新的空数组.

var zero = 0.0
var peopleHeights = Double(player["height"]!)
var totalHeights = zero += peopleHeights!
Run Code Online (Sandbox Code Playgroud)

下面的代码将每个单独的值加倍,而不是我想要的.

var zero = 0.0
var peopleHeights = Double(player["height"]!)
var totalHeights = peopleHeights.map {$0 + $0}
Run Code Online (Sandbox Code Playgroud)

在下面的代码中我得到了响应:Double类型的值没有成员reduce.

var peopleHeights = Double(player["height"]!)
var …
Run Code Online (Sandbox Code Playgroud)

arrays dictionary swift swift3

3
推荐指数
2
解决办法
3686
查看次数

标签 统计

swift ×2

arrays ×1

dictionary ×1

ios ×1

swift2 ×1

swift3 ×1

uitableview ×1