-1

我正在尝试以编程方式使用 addTarget() 为 mainView 中的 UIPageControl 对象添加 ValueChanged 事件。

var pageControls = mainView.subviews.filter { $0 is UIPageControl } as [UIPageControl]
for p in pageControls
{
 println("\(p.tag)"     //p.tag printed as expected
 p.addTarget(self, action: "pageValueChanged:", forControlEvents: .ValueChanged)
}

接着

func pageValueChanged(sender: AnyObject) {
var pageControl = sender as UIPageControl
    println ("value changed")
}

主视图中有 1 个 UIPageControl,我希望当单击 UIPageControl 对象更改其值时会触发 pageValueChanged。但是当单击 UIPageControl 对象时,我得到 error "[Tmoji.KeyboardViewController pageValueChanged:]: unrecognized selector sent to instance"

我对 UIButton 事件 TouchUpInside 做了同样的事情,它起作用了。有什么我错过的吗?

4

1 回答 1

0

一个愚蠢的错误。

事实证明,我的函数 pageValueChanged 被错误地添加到另一个函数中,而不是被添加到类中。

于 2014-10-13T01:01:18.963 回答