1

我通过在控制器的 .h 文件中声明它使其可以访问,
但我不喜欢仅出于测试目的而更改方法的可见性。

有没有其他方法可以使用 Objective-C 调用此方法,
例如。通过临时从测试类改变方法的可访问性?

4

2 回答 2

3

这是override方法,它会自动调用,不需要调用这个方法,或者如果你还想试试,那就放调试器测试一下。

于 2012-04-17T09:23:12.147 回答
3

好的,提醒一下:该方法在苹果类 UIViewController.h 中声明

// Override to allow rotation. Default returns YES only for UIInterfaceOrientationPortrait
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;

所以它是一个公共可访问的方法,你不需要在你的子类 .h 文件中再次声明它

因此,如果您想直接调用它进行测试,只需执行此操作(来自任何引用您的类实例的类):

BOOL rotating = [yourController shouldAutorotateToInterfaceOrientation:1]; 
于 2012-04-17T10:14:49.510 回答