Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 表视图重载数据函数未触发cellForRowAtIndexPath Swift_Ios_Swift_Uitableview_Uisearchbar - Fatal编程技术网

Ios 表视图重载数据函数未触发cellForRowAtIndexPath Swift

Ios 表视图重载数据函数未触发cellForRowAtIndexPath Swift,ios,swift,uitableview,uisearchbar,Ios,Swift,Uitableview,Uisearchbar,我在这里看到过类似的问题,但没有一个对我特别有帮助 我在我的表视图中实现了一个搜索栏,看起来一切正常,没有任何错误。我已经把代码看了好几遍,没有发现任何错误。所以我开始调试 以下是我的搜索功能: func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { var filtered:[Room] = filterz(rooms, txt: searchText) //println(fil

我在这里看到过类似的问题,但没有一个对我特别有帮助

我在我的表视图中实现了一个搜索栏,看起来一切正常,没有任何错误。我已经把代码看了好几遍,没有发现任何错误。所以我开始调试

以下是我的搜索功能:

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {

    var filtered:[Room] = filterz(rooms, txt: searchText)

    //println(filtered.count)

    if(filtered.count == 0){
        searchActive = false
    } else {
        searchActive = true
    }

    self.tView.reloadData()
}
我可以看到,这是完美的工作,因为它是打印出正确的计数。 但是我不确定重载数据功能。 我想它会触发CellForRowatineXpath函数,如下所示:

func  tableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("RoomCell", forIndexPath: indexPath) as! UITableViewCell

    var room:Room = rooms[indexPath.row]

    if(searchActive){
        room = filtered[indexPath.row]
    }

    if let nameLabel = cell.viewWithTag(200) as? UILabel{

        nameLabel.text = room.name
        println(room.name)

    }

    if let sizeLabel = cell.viewWithTag(201) as? UILabel{

        sizeLabel.text = room.size
        println(room.size)

    }

    if let vacLabel = cell.viewWithTag(202) as? UILabel{

        vacLabel.text = room.vacant
        println(room.vacant)

    }

    if let taskIm = cell.viewWithTag(203) as? UIImageView{

        taskIm.image = UIImage(named: room.imagename)
    }

    return cell
} 
正如您所看到的,我已经将print语句放入调试中,但它没有打印任何内容。这是因为函数未触发还是因为我的代码有问题


如果是,有人能找到它吗?我可以肯定的是,在调用
reloadData()
函数之前,一切都工作正常。

最常见的原因是
reloadData
没有调用
cellforrowatinedexpath
是因为您没有正确连接数据源,或者没有引用正确的表视图

确保在
viewDidLoad
中的某个地方有一行如下所示:

self.tView.dataSource = self
查看是否有类似问题的人


此外,通过将
UITableViewCell
子类化并将标签创建为单元格类,您可以更轻松地设置标签。如果让sizeLabel=cell.viewWithTag(201)作为,这将允许您删除整个
?UILabel
dance.

你正在重新澄清你的
var filtered
只需更新你的
cellForRowAtIndexPathindexPath中使用的现有
filtered
,你正在重新澄清你的
var filtered
只需更新现有的
filtered
哈哈,太棒了!好样的!