如何仅在DEBUG和AdHoc模式下执行特定功能 [英] How to execute a specific function only in DEBUG and AdHoc modes

查看:246
本文介绍了如何仅在DEBUG和AdHoc模式下执行特定功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是一个带有操作方法的简单按钮,该按钮被初始化,创建,分配给它的操作方法,并且仅在Debug和AdHoc模式下显示.因此,作为开发人员或测试人员,我可以看到该按钮,但是在发行版中,客户端将无法看到该按钮.

What i would like to do is a simple button with an action method, This button is initialized, created, assigned to its action method and shown ONLY in Debug and AdHoc modes. So as a developer or tester, i can see the button, but in the release, the client won't be able to see that button.

我到目前为止所做的是:

What i did so far is the following:

-在我的project-->Build Settings选项卡中,我将Debug和Adhoc中的Debug值都设置为1,如下所示:

-In my project-->Build Settings Tab, i set the Debug values to 1 in both Debug and Adhoc, like this:

-然后我打开了prefix.pch文件,在那里,我被阻止了,我不知道该怎么办.

-Then i opened up the prefix.pch file, and there, i am blocked and i don't know what to do.

基本上,我的操作方法是这样的:

Basically, my action method is something like this:

UIButton btnSwitch=[[UIButton alloc]init];

//Etc...

以上代码应在特定文件中调用(UIViewController类应包含按钮).

The above code should be called in a specific file (The UIViewController class which should contain the button).

我该怎么做,我的意思是,如何告诉我的应用程序仅在DEBUG和Adhoc模式下在特定文件中执行该代码.

How can i do that, i mean, how can i tell my application to execute that code in a specific file only in DEBUG and Adhoc modes.

先感谢

推荐答案

我不确定您对prefix.pch文件的看法.暂时不要管它.

I'm not sure what your thinking with regards to the prefix.pch file is. Leave that alone for the moment.

您可以在视图控制器中的代码中创建一个按钮,并有条件地这样做.

You can create a button in code inside your view controller and do it conditionally like this.

#ifdef DEBUG
    UIImage *buttonImage = [UIImage imageNamed:@"btnSwitchImage"];

    btnSwitch = [UIButton buttonWithType:UIButtonTypeCustom];
    //frame size given as a point of reference only but when you create a button this
    //way you have to set the frame otherwise you will see nothing.
    btnSwitch.frame = CGRectMake(0.0f, 0.0f, buttonImage.size.width, buttonImage.size.height);
    [btnSwitch setBackgroundImage:buttonImage forState:UIControlStateNormal];

    [btnSwitch addTarget:self action:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btnSwitch];
#endif

这篇关于如何仅在DEBUG和AdHoc模式下执行特定功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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