我找到了很多关于如何通过故事板配置SWRevealViewController的教程,但我希望完全摆脱故事板和xib。
所以我想知道,有没有办法以编程方式配置库?
答案 0 :(得分:3)
您下载的SWReveal软件包中有示例项目。如果我没记错的话,它们都是以编程方式实现的。
来自示例项目#2的AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
self.viewController = mainRevealController;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
答案 1 :(得分:2)
Swift 3
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_group_one"
android:title="SubMenu A">
<menu>
<item
android:checkable="true"
android:title="One"/>
<item
android:checkable="true"
android:title="Two"/>
</menu>
</item>
<item
android:id="@+id/nav_group_two"
android:title="SubMenu B">
<menu>
<item
android:checkable="true"
android:title="Three"/>
<item
android:checkable="true"
android:title="Four"/>
</menu>
</item>
</menu>
答案 2 :(得分:0)
Swift 5.x的更新(以编程方式)
从AppDelegate的didFinishLaunchingWithOptions中:
let revealController = SWRevealViewController()
var mainRevealController = SWRevealViewController()
let sidebar = SideBarViewController()
let homepage = ViewController()
let frontNavigationController = UINavigationController(rootViewController: homepage)
let rearNavigationController = UINavigationController(rootViewController: sidebar)
revealController.frontViewController = frontNavigationController
revealController.rearViewController = rearNavigationController
revealController.delegate = self
mainRevealController = revealController
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = mainRevealController
return true