我有一个包含字典数组的json文件:
"question":"Question text",
"answers":["Yes", "No"],
"answerTracker":["1a", "1b"]
我创建了一个问题类&答案按钮查看班级以显示问题&视图中的答案。
在视图控制器中,我到目前为止已显示问题,创建了答案按钮,最后为每个按钮添加了tapGestureRecogniser。
func answerTapped(gesture:UITapGestureRecognizer) {
// Get access to the button that was tapped
let selectionButtonThatWasTapped:SelectionButtonView? = gesture.view as? SelectionButtonView
if let actualButton = selectionButtonThatWasTapped {
// Find out the index for the button that has been tapped
let selectionTappedIndex:Int? = find(self.selectionButtonArray, actualButton)
**// Find the answer tracker for the button that has been tapped?**
// Append the tracker for the selected button to the User Generated Code
if let actualAnswerTracker:String = self.answerTracker as String! {
self.userGeneratedCode.append(actualAnswerTracker)
}
在上面的tapGestureRecognizer方法中,我现在需要找到相应的answerTracker(String)作为被点击的答案按钮(UIView)但找不到方法?对应于抽头答案的answerTracker字符串将附加到名为userGeneratedCode的String数组属性中。
有什么建议吗?
答案 0 :(得分:1)
您无需向按钮添加dpi
,无论如何都可以向按钮添加目标和选择器。如果您想知道按下了哪个按钮,可以使用width
上的标签属性进行检查。