gpt4 book ai didi

ios - 从 UITableViewCell 调用 UIButton 操作

转载 作者:行者123 更新时间:2023-11-30 13:27:22 26 4
gpt4 key购买 nike

我在 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)
}

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

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

我并不真正关心能够在 UITableViewCell 类中调用它,而是关心在 TableView 类中调用该函数。

有人能解决这个问题吗?

最佳答案

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)
}

关于ios - 从 UITableViewCell 调用 UIButton 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37002308/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com