在.m文件我有一個像如何讓test.m文件中的UIButton的狀態值
-(void) textdata
{
long i = search.text.length;
if (i > 0) {
searchButton.enabled = YES;
}
else
{
searchButton.enabled = NO;
}
[self buttonstate];
}
-(int) buttonstate
{
if ([searchButton isEnabled]) {
j = 1;
}
else
j = 0;
NSLog(@" j value is %d",j);
return j;
}
- (void) textFieldDidChange
{
[self textdata];
NSLog(@"test data is %@",search.text);
}
方法和在tests.m
文件我有測試樣
-(void) testwithoutData
{
myapiViewController *apiViw = [[myapiViewController alloc]init];
[apiViw textdata];
int kn = [apiViw buttonstate];
NSLog(@"the value is %ld",(long)kn);
}
在你的情況下,它實際上是指向零這就是爲什麼你得到j = 0。這是因爲它爲視圖控制器創建了一個新的引用。我認爲你必須在tests.m文件中添加這些方法並手動傳遞值。 – 2015-04-06 14:20:20
請爲我闡述先生 – 2015-04-07 04:38:09