iPhone,如何以编程方式触发按钮事件 [英] iPhone, how to fire a button event in programmatically

查看:58
本文介绍了iPhone,如何以编程方式触发按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在代码中触发一个按钮事件(或方法),该按钮是由iPhone SDK生成的,我无法对其进行更新,因此我向该按钮添加了操作,代码如下:

I want fire a button event(or maybe method) in code,the button was generate by iPhone SDK , I can not update it, so I add the action to the button, the code likes as follows:

[theButton addTarget:self action:@selector(onButtonEvent:) 
       forControlEvents:UIControlEventAllTouchEvents];

 -(void) onButtonEvent:(id)sender
{   
    AppTrace2(self, @"onButtonEvent", sender);   
}

当我点击按钮时,该应用程序将执行由iPhone sdk生成的功能,还将执行新方法"onButtonEvent",然后尝试添加以下代码:

and when I tap the button, the app will execute a function that was produce by iPhone sdk, also the new method 'onButtonEvent' will be executed, and then I try to add some code as follows:

[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事件以调用要执行的函数....

but it does not call the original functions which was produced by iphone sdk, although the new method 'onButtonEvent' also was executed when above sendActionsForControlEvents executed .... my goal is to invoke the original function ... sdk does not provide tip on this , so I have to simulate the tap event to invoke the function to executed ....

任何人都可以给这个问题一个小费吗?

any one can give a tip on this problem ?

感谢您的时间!

致谢

推荐答案

您是什么意思,该按钮是由SDK生成的?您是说按钮是不是您创建的用户界面(例如UIImagePickerControllerMPMoviePlayer界面)的一部分吗?

What do you mean the button was generated by the SDK? Do you mean that the button is part of a user interface not created by you, such as the UIImagePickerController or the MPMoviePlayer interfaces?

如果您发现自己试图在提供的用户界面中添加行为,那么也许您需要重新考虑您的设计? SDK中API提供的用户界面不得修改或扩展.您应该创建自己的界面,如果需要的话,它们看起来会很相似.

If you're finding yourself trying to add behaviour to provided user interfaces, then perhaps you need to rethink your design? User interfaces provided by API's in the SDK shouldn't be modified, or extended. You should create your own interfaces, that can look similar if you want them to.

我不确定您是否打算在完成后将其提交到App Store,但知道过去曾经发生过自动事件(例如按钮按下和触摸事件)导致产生应用的情况被App Store拒绝.

I'm not sure if you're planning on submitting this to the App Store when you're done, but know that there have been cases in the past where automating events, like button presses and touch events have resulted in apps being rejected from the App Store.

一些值得注意的案例是使用流行的Three20库的应用程序,该库模拟了触摸事件以进行测试.简单地讲,即使没有使用模拟的触摸事件(即使没有使用它们),也足以让苹果拒绝使用Three20的应用程序.

Some notable cases were apps using the popular Three20 library, that simulated touch events for testing purposes. Simply the fact that the simulated touch events were left in the code (even if they weren't being used) was reason enough for apple to reject apps using Three20.

这篇关于iPhone,如何以编程方式触发按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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