滑出式菜单VC上的黑屏

时间:2015-08-05 23:47:27

标签: ios objective-c iphone swrevealviewcontroller

我正在使用SWViewController Library。实现库时,我的frontViewController显示但我的rearViewController是黑色的。我不知道造成这个问题的原因,可以使用它。该应用程序完全按目标C编程。此应用程序没有快速也没有故事板。

这是我的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

2 个答案:

答案 0 :(得分:0)

我也在reddit上问过这个问题,here是回答我问题的主题。

事实证明,黑色是SWRevealViewController的默认viewController颜色 - 只是因为它的黑色并不意味着它没有正确加载。

答案 1 :(得分:-1)

之前发生过这件事。视图控制器的默认背景颜色很明显。确保你有背景或至少你的窗口的背景颜色设置。在AppDelegate.m中:

self.window.backgroundColor = [UIColor whiteColor];

另外,我假设你需要一个导航控制器,因为你设置了一个视图控制器self.title属性。当特定视图控制器位于堆栈顶部时,标题将显示在导航栏中。将视图控制器嵌入到navigationController中很简单。将其替换为您设置rootViewController的行。

self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:revealController];