如何在UISegmentedControl中设置选定的段索引? (iPhone SDK) [英] How to set selected segment index in UISegmentedControl? (iPhone SDK)

查看:64
本文介绍了如何在UISegmentedControl中设置选定的段索引? (iPhone SDK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试避免应用程序崩溃...我有一个按钮,它将从UISegmentedControl中删除一个段。如果按下该按钮并且用户已选择要删除的段,则该段将被删除,并且不会突出显示任何选择。但是,当按下另一个按钮执行检索selectedSegmentIndex的操作时,应用程序崩溃。

I'm trying to avoid an app crash here... I have a button that will remove a segment from a UISegmentedControl. If that button is pressed and the user has the segment to be removed selected, the segment will remove and no selection will be highlighted. However, when another button is pushed that does an action that retrieves the selectedSegmentIndex, the app crashes.

简而言之:有没有办法强制在UISegmentedControl中选择一个段?

In short: Is there any way to force the selection of a segment in a UISegmentedControl?

编辑似乎UISegmentedControl在没有选择任何段时返回一个selectedSegmentIndex为-1 ...让我们看看我能从这里做什么。

edit it seems as though the UISegmentedControl is returning a selectedSegmentIndex of -1 when no segment is selected... let's see what I can do from here.

推荐答案

像这样使用.. yourSegmentname.selectedSegmentIndex = 1; //或任何你想要的段

Use like this.. yourSegmentname.selectedSegmentIndex = 1; // or whichever segment you want

这篇关于如何在UISegmentedControl中设置选定的段索引? (iPhone SDK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆