【发布时间】:2023-03-04 13:23:01
【问题描述】:
我已将一个名为按钮状态的方法声明为-(int)buttonstate;
在 xctest.m 中,当我实例化我的 viewController 并分配给一个 int 值时,我得到了错误的值。
-(int) buttonstate {
if ([searchButton isEnabled]) {
j = 1;
}
else
j = 0;
NSLog(@" j value is %d",j);
return j;
}
在 xctest .m 文件中
-(void) testwithoutData {
myapiViewController *apiViw = [[myapiViewController alloc]init];
int kn = [apiViw buttonstate];
NSLog(@"the value is %ld",(long)kn);
}
【问题讨论】:
-
两种方法在同一个视图中?并且您想在其他控制器中传递状态值?
-
如果 UITextField 包含文本,则 uiButton 将启用并且值为 1,我需要 xctest.m 文件中的 j 值如果我在分配视图之前运行测试,我将值设为 0当我在 (int kn ) 中看到它是 0 之后,该值为 1
-
您必须在 testwithoutData 中启用 serachButton,然后才能在运行测试用例时调用 buttonstate 以查看值 1。
-
-(void) textdata { long i = search.text.length;在我运行应用程序时该值为 1,但在 testwithoutData 中,如果 (i > 0) { searchButton.enabled = YES; } else { searchButton.enabled = NO; } [自我按钮状态]; } -(int) buttonstate { if ([searchButton isEnabled]) { j = 1; } 否则 j = 0; NSLog(@" j 值为 %d",j);返回 j; } 我有 textfield.text = @"300";
标签: ios iphone ios6 xcode6 xctest