如何将变量放在按钮目标选择器中

时间:2016-08-23 21:33:55

标签: ios swift uikit selector target-action

我有一个添加目标的按钮,选择器包含一个变量 我可以将变量添加到选择器而不会收到错误吗? 提前谢谢。

//this cause a selector error when run
self.save.addTarget(self, action: #selector(self.saveItems(dataToSave)), forControlEvents: .TouchUpInside)

1 个答案:

答案 0 :(得分:0)

创建一个额外的函数,将其用作动作<div id="nav-buttons"> </div> <script> var totalRecords = 500; var recordsPerPage = 50; var totalButtons = totalRecords/recordsPerPage; var navButtons = document.getElementById("nav-buttons"); console.log(totalButtons) for (var b=0; b<totalButtons;b++) { var button = document.createElement("button"); button.setAttribute("pageto", b); button.innerHTML="Page " + b; navButtons.appendChild(button); button.addEventListener("click", function(event) { var btn = event.target; var page = btn.getAttribute("pageto"); navButtons.appendChild(btn); alert(page); // goto(page) -- write your function for getting the records for page[page] }); } </script>参数

selector

然后添加

func helperFunc() {
    self.saveItems(dataToSave)
}