I need to transfer a string from one tableview
to another by clicking on a button that is inside a UITableView
. I know how to get the indexPath
via a button, like so:
let button = sender as MyButton
let view = button.superview!
let cell = view.superview as! MyTableViewCell
let indexPath = tableView.indexPathForCell(cell)
the above code works to get the indexpath of the cell on a button click, zhowever in order to transfer data, I have to use the prepareForSegue
. So naturally I tried to use prepare for segue and change the sender
from AnyObject
? to MyButton
Then I got an error message saying "overriding method with selector prepareforsegue has incompatible type."
I searched and read about delegates
in swift and how these can help, and I tried the answer given by MakeAppPie here:
Delegates in swift? but it did not work for me.
Is there any way to combine the prepare for segue and the code I have above? I tried this, but it resulted in the error message I just mentioned above:
override func prepareForSegue(segue: UIStoryboardSegue, sender: MyButton) {
let myVC = segue.destinationViewController as? CommentsViewController
let usender:AnyObject = sender!
let button = usender as? MyButton
let view = button.superview!
myVC!.title = button.titleForState(.Normal)
let cell = view.superview as! QuestionCell
let indexPath = tableView.indexPathForCell(cell)
println(self.short_descriptionArray)
var row = self.tableView.indexPathForSelectedRow()?.row
myVC!.nameToGet = short_descriptionArray[row!]
}