我想在代码中触发一个按钮事件(或者可能是方法),按钮是由iPhone SDK生成的,我不能更新它,所以我将操作添加到按钮中,代码如下:
[theButton addTarget:self action:@selector(onButtonEvent:)
forControlEvents:UIControlEventAllTouchEvents];
-(void) onButtonEvent:(id)sender
{
AppTrace2(self, @"onButtonEvent", sender);
}当我点击按钮时,应用程序将执行由iPhone sdk生成的函数,并执行新方法'onButtonEvent‘,然后我尝试添加一些代码,如下所示:
[theButton sendActionsForControlEvents: UIControlEventTouchDown];
[theButton sendActionsForControlEvents: UIControlEventTouchDownRepeat];
[theButton sendActionsForControlEvents: UIControlEventTouchDragInside];
[theButton sendActionsForControlEvents: UIControlEventTouchDragOutside];
[theButton sendActionsForControlEvents: UIControlEventTouchDragEnter];
[theButton sendActionsForControlEvents: UIControlEventTouchDragExit];
[theButton sendActionsForControlEvents: UIControlEventTouchDragInside];
[theButton sendActionsForControlEvents: UIControlEventTouchDragOutside];
[theButton sendActionsForControlEvents: UIControlEventTouchUpInside];
[theButton sendActionsForControlEvents: UIControlEventTouchUpOutside];
[theButton sendActionsForControlEvents:UIControlEventTouchDown];
[theButton sendActionsForControlEvents:UIControlEventAllEvents];但是它没有调用iphone sdk产生的原始函数,尽管在执行上面的sendActionsForControlEvents时也执行了新方法'onButtonEvent‘...我的目标是调用原始函数...sdk没有提供这方面的提示,所以我必须模拟tap事件来调用要执行的函数。
有谁能给出这个问题的提示吗?
耽误您时间,实在对不起!
问候
发布于 2010-02-09 22:50:49
你说按钮是由SDK生成的是什么意思?您的意思是按钮是不是不是由您创建的用户界面的一部分,例如UIImagePickerController或MPMoviePlayer界面?
如果您发现自己正在尝试向所提供的用户界面添加行为,那么您可能需要重新考虑您的设计?SDK中的API提供的用户界面不应被修改或扩展。你应该创建你自己的界面,如果你想让它们看起来相似的话。
我不确定你是否计划在完成后将这篇文章提交到App Store,但我知道过去曾有自动化事件导致应用程序被App Store拒绝的情况。
一些值得注意的案例是使用流行的Three20库的应用程序,该库模拟用于测试的触摸事件。仅仅是因为模拟的触摸事件被留在了代码中(即使它们没有被使用),这就足以让苹果拒绝使用Three20的应用程序。
发布于 2010-02-10 00:24:12
你应该在按钮上调用allTargets,看看它是否返回你想要的目标。如果不是这样,那么任何公共API方法都不会让您达到该目标,这是在浪费时间。
苹果硬连接了它的一些控件,开发人员不能重写它。
Edit01:
UIThreePartButton是一个私有类。如果你使用它的方法,你的应用程序将被应用程序商店拒绝。
然而,我确实找到了一个源代码,它声称是它和它的超类的头部。你可以看看你能不能找到什么。
http://ericasadun.com/iPhoneDocs/_u_i_three_part_button_8h-source.html
即使你不关心拒绝,如果你的最终目标是访问或覆盖API中的某些东西,我认为你是在浪费时间。它不太可能起作用,如果它起作用了,它将变得脆弱。
可能还有另一种方法可以做你想做的事情。
https://stackoverflow.com/questions/2228722
复制相似问题