ios - 如何使用一个瞬时按钮创建 UISegmentedControl?

标签 ios uisegmentedcontrol

我想要一个 UISegmentedControl,其中包含许多 optional ,但还包括一个不可选择的信息按钮。 UISegmentedControl 类引用讨论了使用瞬时披露按钮,暗示它是可能的,但那里或头文件中没有其他内容解释如何做这样的事情。

那我该怎么做呢?

最佳答案

经过多次实验,我发现在所选索引上保留影子变量可以让我做到这一点。在下面的代码中,信息按钮为1,其他按钮都是可选的。在 viewDidLoad 中设置初始值(或向控件询问其选定的索引)。然后在操作方法中使用以下代码:

- (IBAction)segmentAction:(UISegmentedControl *)sender
{
    NSUInteger idx = [sender selectedSegmentIndex];
    switch(idx) {
    case 1:  // momentary button
        sender.selectedSegmentIndex = selectedIndex;
        break;
    default:
        selectedIndex = idx;
        // other stuff
        break;
    }
    ...

基本上,您需要做的就是重置所选索引。仅在 iOS7 上进行了测试。

关于ios - 如何使用一个瞬时按钮创建 UISegmentedControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19097537/

相关文章:

ios - 使用 EKEvent 在 iPhone 中播放闹钟

iphone - UISegmentedControl 选定的段颜色

swift - "-[UIBarButtonItem selectedSegmentIndex]: unrecognized selector sent to instance"用于顶部 UIBar 中的分段控件

ios - 如何在不使用自动布局的情况下设置 UISegmentedControl 子类的高度?

objective-c - 将 UITextField 限制为特定字符范围

javascript - 仅返回一个 <h3> 父标签的文本

ios - 使用 UICollectionView 和自定义流布局时崩溃

cocoa-touch - 如何从分段控件接收输入

ios - 如何在 iOS 9 的一个 View Controller 中处理两个分段 Controller ?

ios - 数组对象加载但未连接到单元格