我将带有委托的数组传递给tableviewcell,在那里我有tableview。然后我将此数组分配给现有数组,因此它应加载到tableview。但它似乎是空的。请帮忙!
func passArray(steps: [Step]) {
self.array = steps
print(steps)
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CellTableViewCell
cell.textView.text = (array[indexPath.row] as! Step).text as String
print(11, array)
return cell
}
这里是我宣布的协议
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedRowIndex = indexPath
let cell = tableView.cellForRowAtIndexPath(indexPath) as! IdeaTableViewCell
editButton.frame = CGRect(x: cell.cellView.frame.size.width - 10, y: 15, width: 20, height: 20)
editButton.setImage(UIImage(named: "change.png"), forState: .Normal)
editButton.addTarget(self, action: "editButtonSegue", forControlEvents: .TouchUpInside)
cell.addSubview(editButton)
cell.cellViewText.text = "\(ideas[indexPath.row].valueForKey("text") as! String). And it is cool because \(ideas[indexPath.row].valueForKey("why") as! String) and it has \((ideas[indexPath.row].valueForKey("steps") as! [Step]).count) steps"
cell.cellViewTextBottomConstraint.constant = cell.tableView.contentSize.height + 16
cell.cellViewText.updateConstraintsIfNeeded()
cell.tableView.updateConstraintsIfNeeded()
cell.tableView.hidden = false
cell.tableView.beginUpdates()
cell.tableView.endUpdates()
delegate1?.passArray(ideas[indexPath.row].valueForKey("steps") as! [Step])
tableView.beginUpdates()
tableView.endUpdates()
}
答案 0 :(得分:1)
首先检查你的数组不能为空,并在调用方法之后用数值填充数组
[self.yourTableViewName reloadData];