滑出式菜单出现黑屏 VC
Black screen on slide-out menu VC
我正在使用 SWViewController Library。实现库时,我的 frontViewController 出现了,但我的 rearViewController 是黑色的。我不知道是什么导致了这个问题,需要一些帮助。该应用程序完全在 Objective C 中编程。此应用程序没有 swift 和故事板。
这是我的 rearViewController.h 代码:
#import <UIKit/UIKit.h>
@interface RearViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) IBOutlet UITableView *rearTableView;
@end
rearViewController.m:
#import "RearViewController.h"
#import "SWRevealViewController.h"
@interface RearViewController()
{
NSInteger _presentedRow;
}
@end
@implementation RearViewController
@synthesize rearTableView = _rearTableView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"Rear View", nil);
}
我的 appDelegate.h 代码:
@class SWRevealViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TARootViewController *rootViewController;
@property (strong, nonatomic) SWRevealViewController *viewController;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
和我的 appDelegate.m 代码:
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "RearViewController.h"
@interface AppDelegate()<SWRevealViewControllerDelegate>
@end
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
RearViewController *rearViewController = [[RearViewController alloc] init];
TARootViewController *frontViewController = [[TARootViewController alloc] init];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
revealController.delegate = self;
self.window.rootViewController = revealController;
[self.window makeKeyAndVisible];
if (self.rootViewController.activeViewController == nil) {
[[TAActiveUserManager sharedManager] startOrResumeAppSession];
}
// Register device for push notifications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
return YES;
}
there is more here but it's not relevant to initializing the viewcontrollers
我以前也遇到过这种情况。视图控制器的默认背景色是清晰的。确保您有自己的背景或至少设置了 window 的背景颜色。在 AppDelegate.m:
self.window.backgroundColor = [UIColor whiteColor];
另外,我假设你想要一个导航控制器,因为你设置了一个视图控制器 self.title 属性。当特定视图控制器位于堆栈顶部时,标题将显示在导航栏中。将视图控制器嵌入到导航控制器中很简单。将其替换为您设置 rootViewController 的行。
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:revealController];
我也在 reddit 上问过这个问题,here 是回答我问题的帖子。
事实证明,黑色是 SWRevealViewController 的默认 viewController 颜色 - 只是因为它是黑色并不意味着它没有正确加载。
我正在使用 SWViewController Library。实现库时,我的 frontViewController 出现了,但我的 rearViewController 是黑色的。我不知道是什么导致了这个问题,需要一些帮助。该应用程序完全在 Objective C 中编程。此应用程序没有 swift 和故事板。
这是我的 rearViewController.h 代码:
#import <UIKit/UIKit.h>
@interface RearViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) IBOutlet UITableView *rearTableView;
@end
rearViewController.m:
#import "RearViewController.h"
#import "SWRevealViewController.h"
@interface RearViewController()
{
NSInteger _presentedRow;
}
@end
@implementation RearViewController
@synthesize rearTableView = _rearTableView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"Rear View", nil);
}
我的 appDelegate.h 代码:
@class SWRevealViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TARootViewController *rootViewController;
@property (strong, nonatomic) SWRevealViewController *viewController;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
和我的 appDelegate.m 代码:
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "RearViewController.h"
@interface AppDelegate()<SWRevealViewControllerDelegate>
@end
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
RearViewController *rearViewController = [[RearViewController alloc] init];
TARootViewController *frontViewController = [[TARootViewController alloc] init];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
revealController.delegate = self;
self.window.rootViewController = revealController;
[self.window makeKeyAndVisible];
if (self.rootViewController.activeViewController == nil) {
[[TAActiveUserManager sharedManager] startOrResumeAppSession];
}
// Register device for push notifications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
return YES;
}
there is more here but it's not relevant to initializing the viewcontrollers
我以前也遇到过这种情况。视图控制器的默认背景色是清晰的。确保您有自己的背景或至少设置了 window 的背景颜色。在 AppDelegate.m:
self.window.backgroundColor = [UIColor whiteColor];
另外,我假设你想要一个导航控制器,因为你设置了一个视图控制器 self.title 属性。当特定视图控制器位于堆栈顶部时,标题将显示在导航栏中。将视图控制器嵌入到导航控制器中很简单。将其替换为您设置 rootViewController 的行。
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:revealController];
我也在 reddit 上问过这个问题,here 是回答我问题的帖子。
事实证明,黑色是 SWRevealViewController 的默认 viewController 颜色 - 只是因为它是黑色并不意味着它没有正确加载。