Các công trình sau đây đối với tôi, nếu tôi sử dụng một cấu trúc dựa trên UISplitViewController
(thử nghiệm trên iOS 8+):
Remove Storyboard từ dự án chung ->Triển khai Thông tin, vì vậy thả xuống trông giống như bên dưới và bạn phải định cấu hình bảng phân cảnh trong mã.
Một nơi nào đó trong AppDelegate.m
- (void)setupViewControllers
{
// check for thread, as this method might be called by other (e.g. logout) logic
if ([NSThread currentThread] != [NSThread mainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self setupViewControllers];
});
return;
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *vc =[storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = vc;
// configure split vc
// Note: I reference split vc for my own purpose, but it is your mater of choice
self.splitViewController = (UISplitViewController *)self.window.rootViewController;
self.splitViewController.delegate = self;
self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
self.splitViewController.preferredPrimaryColumnWidthFraction = 0.5;
[self.window makeKeyAndVisible];
}
Để tránh trùng lặp mã, gọi chức năng này từ application:didFinishLaunchingWithOptions:
như một thiết lập lần đầu
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// some code...
[self setupViewControllers];
// Optional: add splash view (e.g. [self addSplashView];)
// some code...
}
Bên trong một bộ điều khiển xem bạn đã sẵn sàng hiển thị giao diện người dùng cho người dùng, loại bỏ chế độ xem giật gân.Ví dụ: (trong Swift):
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if !AppSession.currentSession().isLoggedIn() {
presentLoginViewController(false, completion: {()->Void in
self.removeSplash()
})
}
else {
removeSplash()
}
// some code...
}
private func removeSplash() {
if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {
appDelegate.removeSplashView()
}
}
Nguồn
2015-11-24 10:06:18
Bạn đã bao giờ tìm ra điều này chưa? Tôi có chính xác nhu cầu tương tự cho điều này ... –