小编Joe*_*ren的帖子

理解方法使用!=返回BOOL

这是关于shouldAutoRotateToInterfaceOrientation视图控制器方法中return语句的语法的一个相当基本的问题.

为了允许除了颠倒的肖像模式之外的所有视图,我实现了以下代码块:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)

退货声明究竟在做什么?我知道它返回一个布尔变量,但它是如何确定是返回true还是false?这是return语句中的一种隐式if语句吗?即:

-    (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown)
        return YES;
}
Run Code Online (Sandbox Code Playgroud)

技术上是一样的,只是更明确地说明了吗?

谢谢你的澄清!

boolean objective-c return-value ios

4
推荐指数
1
解决办法
8403
查看次数

标签 统计

boolean ×1

ios ×1

objective-c ×1

return-value ×1