从UITableViewCell调用UIButton操作

时间:2016-05-03 11:01:36

标签: ios swift uitableview uibutton

我在UITableviewCell类中动态创建了几个按钮,如下所示:

for (clientObjectId, _) in connectedObjectIds {
    self.clientNameButton = UIButton(type: UIButtonType.System) as UIButton
    self.clientNameButton.titleLabel?.lineBreakMode = NSLineBreakMode.ByTruncatingTail
    self.clientNameButton.frame = CGRectMake(self.leftSideSpaceForUsersAndUserLabel, clientNameButtonFrameHeight, self.nameButtonWidth, self.nameButtonHeight)
    self.clientNameButton.setTitle(self.userObjectIdsAndNames[clientObjectId], forState: UIControlState.Normal)
    self.clientNameButton.titleLabel!.font = UIFont(name: "Helvetica", size: 12.0)
    self.clientNameButton.addTarget(self, action: "asdf:", forControlEvents: UIControlEvents.TouchUpInside)
    self.nameButtons.append(self.clientNameButton)
    self.addSubview(self.clientNameButton)
}

但是,我似乎找不到在表格视图单元类中调用以下函数的方法:

func asdf(sender:UIButton) {
     print("Button tapped")
}

我并不十分关心能够在我的UITableViewCell类中调用它,就像我在表视图类中调用函数一样。

有人能解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

<bar item="model.selectedItem" />
<ol>
<li ng-repeat="item in model.items" ng-click="model.selectItem(item)">
    <bar item="item" />
</li>
</ol>