在表视图中处理多个UISwitch控件,而不使用标记属性 [英] Handling multiple UISwitch controls in a table view without using tag property

查看:215
本文介绍了在表视图中处理多个UISwitch控件,而不使用标记属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图控制器,其中有多个UISwitch控件。我将委托设置为表视图控制器,对所有交换机采用相同的操作。我需要能够确定什么开关被改变,所以我创建一个字符串数组,包含每个开关的名称。数组中的索引将被放在每个UISwitch的标签属性中。

I have a table view controller with multiple UISwitch controls in them. I set the delegate to the table view controller with the same action for all switches. I need to be able to determine what switch was changed, so I create an array of strings that contains the name of each switch. The indexes in the array will be put in the tag property of each UISwitch.

但是,我已经准备好使用tag属性的东西,控制在cellForRowAtIndexPath与viewWithTag的单元格! (我需要在每个单元格内设置几件事情。)

However, I'm ready using the tag property for something else, namely to find the right control in the cell in cellForRowAtIndexPath with viewWithTag! (There are several things I need to set within each cell.)

那么,我在这里沿着正确的线吗?我觉得我非常有限,如何确定哪个UISwitch改变了它的价值,所以我可以做一些有用的东西。

So, am I thinking along the right lines here? I feel I'm rather limited in how I find out exactly which UISwitch changed its value, so I can do something useful with it.

推荐答案

我通过子类化UISwitch像这样固定这:

I fixed this by subclassing UISwitch like so:

@interface NamedUISwitch : UISwitch {
NSString *name;

}

索引数组需要)和标签属性可以随意做任何它想要的。

It seems elegant (no index arrays required) and the tag property is free to do whatever it wants.

我读到你必须小心在Objective-C子类化,虽然...

I read that you have to be careful with subclassing in Objective-C, though...

这篇关于在表视图中处理多个UISwitch控件,而不使用标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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