Reputation: 133
I pass an array with delegation to tableviewcell, where I have tableview. Then I assign this array to an existing array so it should load to tableview. But it seems to be empty. Please, help!
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
}
and here is where I have declared protocol
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()
}
Upvotes: 0
Views: 74
Reputation:
First of all check your array must not be empty and where you fill your array with values after that call the method
[self.yourTableViewName reloadData];
Upvotes: 1