gpt4 book ai didi

iphone - 如何仅在 DEBUG 和 AdHoc 模式下执行特定功能

转载 作者:行者123 更新时间:2023-11-28 17:58:52 24 4
gpt4 key购买 nike

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

到目前为止我所做的是:

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

enter image description here

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

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

UIButton btnSwitch=[[UIButton alloc]init];

//Etc...

上面的代码应该在特定的文件中调用(应该包含按钮的 UIViewController 类)。

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

提前致谢。

最佳答案

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

您可以在 View Controller 内的代码中创建一个按钮,并像这样有条件地执行它。

#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

关于iphone - 如何仅在 DEBUG 和 AdHoc 模式下执行特定功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11132287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com