【发布时间】:2015-06-13 01:40:57
【问题描述】:
我有一个自定义的UIButton,我需要将它添加到我的动态表格视图单元格中。我用过的教程都不适合我。我的UIButton 仅在单击单元格时出现,然后迅速消失。当我单击按钮时,应用程序崩溃,我得到...ViewController addButtonPressed]: unrecognized selector sent to instance。我需要在这里做什么?
class TableViewCell: UITableViewCell {
@IBOutlet weak var addFriendButton: UIButton!
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBAction func addButtonPressed(sender: UIButton!) {
println("Hey")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var friendsCell = tableView.dequeueReusableCellWithIdentifier("AddFriendsCell", forIndexPath: indexPath) as! TableViewCell
friendsCell.addFriendButton.tag = indexPath.row
friendsCell.addFriendButton.addTarget(self, action: "addButtonPressed", forControlEvents: .TouchUpInside)
return friendsCell
}
}
【问题讨论】:
标签: ios swift uitableview uibutton