【发布时间】:2016-01-13 10:32:25
【问题描述】:
我正在使用从后端获取的名称列表填充一个表(作为用户名,然后作为朋友的名字)。
数组显示所有内容都在那里(它应该包含 2 条记录),但由于某种原因,我正在做一些愚蠢的事情,导致表格视图中只显示一条记录(单行)。
我个人认为这是由于实现了 cellForRowAtIndexPath 方法而导致的错误。代码如下:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let cellIdentifier = "cell"
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? FriendsCell
if cell == nil {
cell = FriendsCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
}
// Configure the cell to show name of friend
print("Index Row: \(indexPath.row)")
cell!.name.text = self.friendsInfoListArray[indexPath.row]["name"] as? String
return cell
}
有人能看出哪里出错了吗?如前所述,数组中有两条记录,但只显示一条。
谢谢
更新:
reloadTable 的代码:
override func queryForTable() -> PFQuery {
self.loadFriendsUsernames({ (result)->Void in
if(result.count > 0)
{
self.loadFriendsInfo({ (result)->Void in
if(result.count > 0)
{
print(self.friendsInfoListArray)
self.tableView.reloadData()
print("Success Loading Friends Info Array")
}else{
print("Error Loading Friends Info Array")
}
})
}else{
print("Error Loading Friends Usernames Array")
}
})
let query = PFQuery(className: self.parseClassName!)
let currentUser = PFUser.currentUser()
query.whereKey("appUsername", equalTo: currentUser!["appUsername"])
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if self.objects!.count == 0 {
query.cachePolicy = .CacheThenNetwork
}
return query
}
【问题讨论】:
-
在您的 numberOfRowsInSection 方法中,您返回什么值?是数组的计数,还是只有 1。
-
你实现了numberOfRowsInSection函数吗?
-
@totiG 很好地实现了捕获,但将其留空。我添加了所需的内容,但现在又出现另一个错误,显示“NSRangeException”,原因:'*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'”
-
这可能是因为 numberOfRows 部分返回的行数比数组中的行数多。您的 numberOfRows 实现是否设置为:return friendsInfoListArray.count
-
@totiG 是的,确实是....更好的方法?
标签: ios xcode swift parse-platform