本文介绍了为UISegmentedControl定义单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中添加了 UISegmentedControl 。在正常状态下没有选择任何按钮。我希望在选择第一个段时实现按钮单击事件,并在单击另一个按钮时实现另一个事件。

I have added a UISegmentedControl in my application. None of the buttons are selected in normal state. I want to implement a button click event when the first segment is selected, and another event when another button is clicked.

推荐答案

如果我理解你的问题,你只需要实现一个目标 - 动作方法(由这是 UISegmentedControl 的父类),用于常量 UIControlEventValueChanged ,与UISegmentControl的中给出的示例完全相同。

If I understand your question correctly, you simply have to implement a target-action method (supported by UIControl which is UISegmentedControl's parent class) for the constant UIControlEventValueChanged, exactly like in the example given in UISegmentControl's reference documentation.

ie

[segmentedControl addTarget:self
                     action:@selector(action:)
           forControlEvents:UIControlEventValueChanged];

用于带有以下签名的邮件:

used for a message with the following signature:

- (void)action:(id)sender

[segmentedControl addTarget:self
                     action:@selector(action:forEvent:)
           forControlEvents:UIControlEventValueChanged];
- (void)action:(id)sender forEvent:(UIEvent *)event

[segmentedControl addTarget:self
                     action:@selector(action)
           forControlEvents:UIControlEventValueChanged];

最简单的方法:

- (void)action

这是标准类型的目标动作UIKit中使用的选择器。

which are standard types of target-action selectors used in UIKit.

这篇关于为UISegmentedControl定义单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:22