一个 UIView 中的多个 UISwitch 项目
那么我想问一下如何在一个 UIview 上配置 7 个 UISwitch?我将开关放置在界面生成器中,然后我想通过代码来管理它们。管理这个问题的最佳方法是什么。这是我的 .h 到目前为止,
#import <UIKit/UIKit.h>
@interface searchEditViewController : UIViewController{
UISwitch *switchOne;
UISwitch *switchTwo;
UISwitch *switchFor;
UISwitch *switchFive;
UISwitch *switchSix;
UISwitch *switchSeven;
}
@property(nonatomic,retain)UISwitch *switchOne;
@property(nonatomic,retain)UISwitch *switchTwo;
@property(nonatomic,retain)UISwitch *switchThree;
@property(nonatomic,retain)UISwitch *switchFour;
@property(nonatomic,retain)UISwitch *switchFive;
@property(nonatomic,retain)UISwitch *switchSix;
@property(nonatomic,retain)UISwitch *switchSeven;
-(IBAction)toggleButtonPressed:(id)sender;
@end
我想创建一个操作方法toggleButtonPressed 来处理其中的七个
Possible Duplicate:
Handling multiple UISwitch controls in a table view without using tag property
Well i want to ask how can i configure 7 UISwitches on one UIview? I place the switches with interface builder and then i want to manage them through code. What is the best way of managing this. Here is my .h so far
#import <UIKit/UIKit.h>
@interface searchEditViewController : UIViewController{
UISwitch *switchOne;
UISwitch *switchTwo;
UISwitch *switchFor;
UISwitch *switchFive;
UISwitch *switchSix;
UISwitch *switchSeven;
}
@property(nonatomic,retain)UISwitch *switchOne;
@property(nonatomic,retain)UISwitch *switchTwo;
@property(nonatomic,retain)UISwitch *switchThree;
@property(nonatomic,retain)UISwitch *switchFour;
@property(nonatomic,retain)UISwitch *switchFive;
@property(nonatomic,retain)UISwitch *switchSix;
@property(nonatomic,retain)UISwitch *switchSeven;
-(IBAction)toggleButtonPressed:(id)sender;
@end
I want to make one action method toggleButtonPressed that will take care the seven of them
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为所有
UISwitch
对象创建一个操作(我猜这是toggleButtonPressed
)。现在在这个方法中你可以知道哪个 UISwitch 被触发了:编辑。您可以将
tag
属性设置为某个值(从 1 到 7),并将if-statement
更改为switch-case
。Create one action for all
UISwitch
objects (I guess this istoggleButtonPressed
). In this method now you can know which UISwitch was triggered:Edit. You can set
tag
property to some value (from 1 to 7) and changeif-statement
toswitch-case
.@beryllium,你的方法确实有效,但你可能想尝试一些更优雅的方法。
相反,标记每个开关,然后使用 switch-case 代替 if-then,正如您似乎已注释掉的那样。
这是一个示例,请注意 kUIActivityIndicatorViewStyleWhiteLarge 实际上是我创建并分配了一个值的常量
#define kUIActivityIndicatorViewStyleWhiteLarge 1
如果您想按照自己的方式进行操作,那是可以的,但同样不太理想。但是,如果这样做,则代码:
是多余的。相反,您可以写以下内容:
我希望有帮助。
我创建了一个应用程序来测试不同颜色背景上的 UIActivityIndicatorView 样式,它使用滑块和开关。如果有人想查看带有 IB 组件的应用程序,请访问以下网址:
https://github.com/asadquraishi/UIActivityIndicatorView -测试
@beryllium, your way does work but you might want to try something a little more elegant.
Instead, tag each switch and then instead of if-then use switch-case as you appear to have commented out.
Here's an example, note that kUIActivityIndicatorViewStyleWhiteLarge is actually a constant I created and assigned a value
#define kUIActivityIndicatorViewStyleWhiteLarge 1
If you want to do it your way, that's OK but again less optimal. However if you do, the code:
is redundant. instead you can wrote the following:
I hope that helps.
I created an app to test UIActivityIndicatorView styles on different coloured backgrounds and it uses sliders and switches. Here the url if anyone wants to see the app with IB components:
https://github.com/asadquraishi/UIActivityIndicatorView-Test