UIControl (addTarget:action:forControlEvents:) @selector 参数
@selector(updateStuff:)
这会自动发送参数:(id)sender。是否可以将其覆盖为其他内容?在我的特定用法中,实际的发送者是没有意义的。
我正在使用 UITableView 并在每个单元格的 UIAccessoryView 插槽中设置 UISwitch。最初,我在单元初始化之外将 UISwitch 添加到 UIAccessoryView,这允许每个 UISwitch 成为唯一的实例。然而,在 iPhone 3G 上向下滚动长列表时,这会产生明显的延迟。如果我在初始化时将 UIAccessoryView 添加到单元格中,它可以出队而不是实例化,并大大缓解延迟。不幸的是,这样做的代价是,该实例对于表中的每个 UISwitch 来说并不是唯一的,并且 :(id)sender 变得毫无意义。
我需要两件事之一......
- 一种覆盖参数的方法 与@selector关联,所以我可以 替换 :(id)sender
- 或者比我使用的策略更好的策略 跟踪 UISwitches。
我总是可以在单元格创建/出列后添加 UISwitch,但它非常慢且效率低下。感谢您的任何帮助。
真挚地, Z@K!
@selector(updateStuff:)
This is automatically sends the parameter :(id)sender. Is it possible to override this to be something else? In my particular usage, the actual sender is meaningless.
I'm using a UITableView and setting a UISwitch in the UIAccessoryView slot on every cell. Originally, I was adding the UISwitch to the UIAccessoryView outside of the the cell initialization, which allowed each UISwitch to be a unique instance. However this creates a noticeable lag while scrolling down long list on the iPhone 3G. If I add the UIAccessoryView to the cell when it's initialized, it can be dequeued instead of instantiated and eases the lag considerably. Unfortunately, the cost of doing this is, the instance is NOT unique to each UISwitch in the table, and :(id)sender becomes meaningless.
I need one of two things...
- A way to override the parameter
associated to @selector, so I may
replace :(id)sender - Or a better strategy than the one I am using to
keep track of the UISwitches.
I can always resort to adding the UISwitch after the cell is created/dequeued but it is terribly slow and inefficient. Thanks for any help.
Sincerely,
Z@K!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我编写了一个 UISwitch 子类,其中包含用于值更改控制事件的基于块的处理程序,这在尝试跟踪哪个开关的值已更改时可以提供帮助。理想情况下,我们可以对组合而不是子类化做类似的事情,但这很适合我的需求。
https://gist.github.com/3958325
你可以这样使用它:
你也可以使用它从 XIB 文件中,将开关拖到视图上,然后将其类更改为 ZUISwitch
I have written a UISwitch subclass with a block based hander for value change control events which can help when trying to track which switch's value has changed. Ideally, we could do something similar with composition rather than subclassing, but this works well for my needs.
https://gist.github.com/3958325
You can use it like this:
You can also use it from a XIB file, by dragging a switch onto your view, and then changing its class to ZUISwitch
很多很多方法:
while (v && ![v isKindOfClass:[UITableViewCell class]]) {v = v.superview; }
)。[tableView indexPathForCell:(UITableViewCell*)v]
。Many, many ways:
while (v && ![v isKindOfClass:[UITableViewCell class]]) {v = v.superview; }
).[tableView indexPathForCell:(UITableViewCell*)v]
.我有一个类似的问题,我解决它的方法是通过设置发件人的“标签”属性,每个视图都有这个属性,目的是帮助识别它。因此,在创建/出列单元格时,设置标记来标识单元格,并在操作中使用 [sender tag] 来获取单击的上下文
I had a similar problem, the way I've solved it is by setting the "tag" property of the sender, every view has this property and purpose is to help identify it. So while creating/dequeueing the cell set the tag to identify the cell, and on the action use [sender tag] to get the context of the click