使用std :: vector :: begin vs begin(vector)(Use std::vector::begin vs begin(vector))
如果我有
std::vector
(这是一个std::vector
并且总是一个std::vector
)。是否优于使用
std::begin()
而不是std::vector::begin()
(或相反)?是否有任何性能增加/减少?
例:
std::vector<int> foo(100, 5); std::sort(foo.begin(), foo.end()); // Case 1 std::sort(std:begin(foo), std::end(foo)); // Case 2
If I have
std::vector
(which is astd::vector
and will be always astd::vector
).Is it superior to use
std::begin()
instead ofstd::vector::begin()
(or the opposite)?Will there be any performance increase/decrease?
Example:
std::vector<int> foo(100, 5); std::sort(foo.begin(), foo.end()); // Case 1 std::sort(std:begin(foo), std::end(foo)); // Case 2
原文:https://stackoverflow.com/questions/35431537
最满意答案
可能的根本原因
我有同样的问题,并且发现它正在发生,因为我没有在我的应用程序窗口中设置根视图控制器。
在其中实现了
preferredStatusBarStyle
的UIViewController
在UITabBarController
,它控制了屏幕上的视图的外观。当我将根视图控制器设置为指向此
UITabBarController
,状态栏更改开始正常工作,正如预期的那样(并且preferredStatusBarStyle
方法被调用)。(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // other view controller loading/setup code self.window.rootViewController = rootTabBarController; [self.window makeKeyAndVisible]; return YES; }
替代方法(iOS 9中已弃用)
或者,您可以根据自己的背景颜色,在每个视图控制器中根据需要调用以下方法之一,而不必使用
setNeedsStatusBarAppearanceUpdate
:[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
要么
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
请注意,如果您使用此方法,您还需要在plist文件中将
UIViewControllerBasedStatusBarAppearance
设置为NO
。Possible root cause
I had the same problem, and figured out it was happening because I wasn't setting the root view controller in my application window.
The
UIViewController
in which I had implemented thepreferredStatusBarStyle
was used in aUITabBarController
, which controlled the appearance of the views on the screen.When I set the root view controller to point to this
UITabBarController
, the status bar changes started to work correctly, as expected (and thepreferredStatusBarStyle
method was getting called).(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // other view controller loading/setup code self.window.rootViewController = rootTabBarController; [self.window makeKeyAndVisible]; return YES; }
Alternative method (Deprecated in iOS 9)
Alternatively, you can call one of the following methods, as appropriate, in each of your view controllers, depending on its background color, instead of having to use
setNeedsStatusBarAppearanceUpdate
:[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
or
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
Note that you'll also need to set
UIViewControllerBasedStatusBarAppearance
toNO
in the plist file if you use this method.
相关问答
更多-
为什么我的NSAlert中的didEndSelector不被调用?(Why isn't my didEndSelector in my NSAlert being called?)[2023-11-21]
尝试在切换之前插入此行: NSLog(@"code: %ld", code); Try to insert this line just before the switch: NSLog(@"code: %ld", code); -
这在ActionBarSherlock中是不可避免的,我在检查github上的问题页面时忽略了这个问题。 基本上,嵌套片段中选项菜单的功能尚未添加,请参阅: https : //github.com/JakeWharton/ActionBarSherlock/issues/828 。 我现在的解决方案是用注释中的修改文件之一替换Watson.java。 It was, somewhat inevitably, an issue with ActionBarSherlock that I'd overlook ...
-
最后,我使用了一种交叉点击方法,在适配器分配给每个视图的内部onClick()侦听器中调用我想要的onItemClickListener回调.... 有点像这样 public SomeAdapter(Context context, int textViewResourceId, List
objects, OnItemClickListener clickListener) { super(context, textViewResourceId, objects) ... -
onPostExecute不被调用(onPostExecute is not called)[2022-01-21]
看起来你错过了一些东西 @Override protected void onPostExecute(Void result) { super.onPostExecute(result); if (exception.contains("java.net.UnknownHostException")) { MainActivity.showDialog(); Log.i("Error Message", "ERROR MESSAGE SHOWN"); ... -
可能的根本原因 我有同样的问题,并且发现它正在发生,因为我没有在我的应用程序窗口中设置根视图控制器。 在其中实现了preferredStatusBarStyle的UIViewController在UITabBarController ,它控制了屏幕上的视图的外观。 当我将根视图控制器设置为指向此UITabBarController ,状态栏更改开始正常工作,正如预期的那样(并且preferredStatusBarStyle方法被调用)。 (BOOL)application:(UIApplication *) ...
-
为什么不叫@Before(Why isn't @Before being called)[2022-10-14]
从您的代码中删除extends TestCase 。 例如: import org.junit.After; import org.junit.Before; import org.junit.Test; public class CalcDateToolTest { DatesCalculator calc; @Before public void initialize() { System.out.println("Before"); calc ... -
我从Foxandxss得到了Angular频道对irc的回答,这就是他所说的。 有两种不同的注射位置服务,控制器,指令,运行哦和过滤器,你可以注入服务但不是提供者那么,你有另一个注入位置,提供者和配置功能,你只能注入常量和提供者所以提供者有两个如果你将提供者注入另一个提供者或配置你注入配置部分,你必须在名称上附加提供者,所以当你将“提供者部分,即配置”和“工厂”分成它时,它就是$ get注入“unicornLauncher”到配置你应该把“unicornLauncherProvider”注入配置部分,而不是 ...
-
为什么变量“preferredStatusBarStyle”删除标签栏?(Why would variable “preferredStatusBarStyle” remove the tab bar?)[2022-10-02]
与您的代码一起,In Info.plist将基于视图控制器的状态栏外观视为NO Along with your code, In Info.plist put View controller-based status bar appearance as NO -
使用此代码获取confi chage override fun onConfigurationChanged(newConfig: Configuration?) { super.onConfigurationChanged(newConfig) if (newConfig != null) { if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { ...
-
我想通了,基本上我没想到。 激活导体/根视图的构造函数中的视图无法正常工作,因为它尚未激活。 在调用指挥/根视图的OnActivate之前, IsActive不会设置为true。 这在某些时候可能是有问题的,因为即使调用OnInitialize时导体也不活动,并且这意味着一次初始化函数和OnActivate可以被多次调用。 在我的情况下它会很好,因为我的指挥是根视图所以OnActivate只会被调用一次。 故事的道德是,当导体是根视图时,不要在导体的构造函数中调用ActivateItem 。 I figur ...