1

I have two classes UIVIewController and UITableviewcell. In UITableviewcell, i have a button and the button action should be in UIViewController. How can i pass a class and set delegate in button action.

i tried this code,

//UIVIewController

cell.createButton(self)


func buttonClick(object:AnyObject){
  println("Button Clicked")
}

//UITableViewCell

func createButton(delegate:AnyObject){
//button created.

    button.addTarget(delegate, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
}

But the above code is not working. 'buttonClick' function is not calling

iPhone Guy
  • 1,285
  • 3
  • 23
  • 34

1 Answers1

0

I had the same problem a while ago, trying to put self in place of "delegated".

otherwise try to take a look at this question:

link

I hope to be helped.

Community
  • 1
  • 1
uynva
  • 97
  • 1
  • 16
  • Ok. Thanks. It's working. But i wonder, is this is the correct way of doing. In objective c, i think we can pass a delegate and set target in UITableview cell class. why it is not possible with swift? – iPhone Guy Nov 05 '14 at 04:49
  • actually it should work like you wrote the code, I do not know if it's a bug or is written in a different way. However Self works :) – uynva Nov 05 '14 at 11:49