【发布时间】:2015-09-06 23:23:08
【问题描述】:
我正在制作一个类似于 Yelp 的应用程序。在视图控制器中,我有 2 个视图:带有一个名为“列表”的插座的 UITableView 和一个 mapView。在顶部我有一个搜索栏。
填充表格视图通常很简单,但我没有使用 UITableViewController,所以有点混乱。
在最顶部,我添加了一个全局变量
var cell: UITableViewCell?
然后在一个表函数中,我有
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("attractionCell") as! AttractionCell!
if cell == nil {
cell = AttractionCell(style: UITableViewCellStyle.Default, reuseIdentifier: "attractionCell")
}
cell.attractionName.text = title
return cell
}
在底部,我有一个用于单击搜索栏时的功能,然后它从 Parse 中获取数据,并将对象的名称分配给一个名为“title”的变量。
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
var Query = PFQuery(className:"Stores")
Query.whereKey("Location", nearGeoPoint:area, withinMiles: 5)
Query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
let objects = objects as! [PFObject]
for object in objects {
let title = object["name"] as! String
self.cell?.attractionName.text = title
为什么我的表格视图没有填充?
另外,在情节提要中,tableView 中的原型单元格属于 AttractionCell 类,并且有一个称为吸引单元的重用标识符
【问题讨论】:
-
和tableview的行数有关系吗?
-
您是否将 tableView 链接到委托和数据源?您的控制器是否符合(
UITableViewDelegate和)UITableViewDataSource?
标签: swift uitableview uisearchbar