ios - UIButton 执行 UISegment 控件操作

标签 ios uibutton uisegmentedcontrol

我的应用程序中有一个 UISegmented 控件。我还有一个自定义按钮。我希望这个自定义按钮将 Segment 返回到 index 0 但也执行 index 0 的方法。

这是我的分段控件;

- (IBAction)segmentSwitch:(id)sender {
  UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
  NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;

  if (selectedSegment == 0) {
  //perform custom action

  }
  else if(selectedSegment ==1){

  }
  else if (selectedSegment ==2){

 //show custom button


 }

}

我的按钮是;

-(IBAction)buttonAction: (id)sender{

 //deselect index 2 of segmented control

 //go to index 0
 //perform index 0s method
}

我的按钮有什么方法可以为 index 0 执行 segmentSwitch 操作吗?

最佳答案

只需从按钮的目标方法中调用 segmenteSwitch 方法:

 -(IBAction)buttonAction: (id)sender{

     self.segmentedControl.selectedIndex = 0;
     [self segmentSwitch:self.segmentedControl];
 }

关于ios - UIButton 执行 UISegment 控件操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26162018/

相关文章:

ios - 在 iOS 中绘制气泡图?

ios - 如何以编程方式向 xib 添加约束

iphone - 制作 Activator 监听器时遇到问题(使用 theos)

iphone - UIButton 选择器在主窗口 View 上不起作用

ios - UINavigationController 大标题和多个 UIScrollViews/UITableViews

ios - 如何在单个 UI 按钮上启动和停止五彩纸屑 View ?

ios - 单击将带有 UIButton 的 UIView 添加到 UIWindow

ios - 如何为按钮设置动画以显示右侧 View 并在点击时弹回

ios - UISegmentedControl - 最后一段不容易选择

ios - 使用 Swift 的单个 TableView 在 2 个数据模型之间传输数据