gpt4 book ai didi

ios - 在运行时获取主 Storyboard

转载 作者:IT王子 更新时间:2023-10-29 08:14:28 26 4
gpt4 key购买 nike

我希望能够在运行时简单地调用 [UIStoryboard mainStoryboard] 来获取 iPad 或 iPhone Storyboard。

最佳答案

这是一个 UIStoryboard 类别,它会做这个:

UIStoryboard+LDMain.h

#import <UIKit/UIKit.h>

@interface UIStoryboard (LDMain)

+ (instancetype)LDMainStoryboard;

@end

UIStoryboard+LDMain.m

#import "UIStoryboard+LDMain.h"

UIStoryboard *_mainStoryboard = nil;

@implementation UIStoryboard (LDMain)

+ (instancetype)LDMainStoryboard {
if (!_mainStoryboard) {
NSBundle *bundle = [NSBundle mainBundle];
NSString *storyboardName = [bundle objectForInfoDictionaryKey:@"UIMainStoryboardFile"];
_mainStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle:bundle];
}
return _mainStoryboard;
}

@end

这是一个 link to the gist

关于ios - 在运行时获取主 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19327646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com