I am trying to add some buttons dynamically in UITableViewCell.I have created method "tappedButton" which is supposed to call when any of those buttons get clicked but its not working properly. I need to press 3 or 4 times and then hardly the action happens.Can anyone suggest me a better way to do this.

```
    func tappedButton(sender: UIButton!) {
            print("tapped button---->"+(sender.titleLabel?.text)!)
            self.performSegueWithIdentifier("web", sender: self)
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! MagazineTableViewCell
                 // headings is global variable , an array of string
                 for td in headings {
                    let button:UIButton = UIButton(frame: CGRectMake(0, t, 500, 26))
                    t+=36
                    button.setTitle(td,forState: UIControlState.Normal)
                    let black=hexStringToUIColor("#000000")
                    let white=hexStringToUIColor("#ffffff")
                    button.backgroundColor = black
                    button.setTitleColor(white, forState: UIControlState.Normal)
                    button.addTarget(self, action: #selector(MainTableViewController.tappedButton(_:)), forControlEvents: UIControlEvents.AllTouchEvents)
                    // searchView is a black UIView in which I dynamically add buttons
                    cell.searchView.addSubview(button)
                  }

         return cell
    }

```