【问题标题】:Black screen on slide-out menu VC滑出式菜单 VC 上的黑屏
【发布时间】:2015-10-28 22:39:15
【问题描述】:

我正在使用SWViewController Library。实现库时,我的 frontViewController 出现了,但我的 backViewController 是黑色的。我不知道是什么导致了这个问题,并且可以使用一些帮助。该应用程序完全使用 Objective C 编程。该应用程序没有 swift 也没有情节提要。

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

【问题讨论】:

  • 我正在使用断点进行调试,并在 viewDidLoad 函数结束之前在 RearViewController.m 中设置断点返回的值不是 nil,这意味着视图确实存在于内存中的某个位置
  • 在这方面 SWRevealController 库似乎存在一些问题。谷歌搜索结果:Had the same issue. Setting revealAnimationType = SWRevealToggleAnimationTypeEaseOut fixes it but I liked SWRevealToggleAnimationTypeSpring better.
  • 这似乎是旧版本库的过时修复。更改库中默认属性列表中的属性并没有解决这个问题。
  • link 问题

标签: ios objective-c iphone swrevealviewcontroller


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我以前也遇到过这种情况。视图控制器的默认背景颜色是清晰的。确保您设置了背景或至少设置了窗口的背景颜色。在 AppDelegate.m 中:

    self.window.backgroundColor = [UIColor whiteColor];
    

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

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

    【讨论】:

    • 感谢您的评论!库中的说明和示例与您发布的内容略有不同,因为我必须将 SWRevealViewController 设置为库的根视图控制器才能正常工作。另外,我在哪里设置 appdelegate.m 中的背景颜色?如何指定它仅用于滑出菜单? (其余视图正确加载)提前对任何菜鸟问题表示歉意 - 我对 iOS 编码非常陌生。我选择了 C 而不是 Swift,因为我有一些编程经验,而不是 Swift/Storyboards。
    • 只要在窗口初始化和makeKeyandVisible之间的任意位置设置ViewDidLoad即可。我通常只是在[self.window makeKeyAndVisible] 之前做。是的,不用担心我当时说的导航部分。此外,每个 viewController 都有一个 .backgroundColor 属性,因此如果您想排除故障并查看当前堆栈中的哪个 viewController,只需将它们中的每一个设置为不同的颜色。
    • 嗯,有道理。顺便说一句,在库文件中,默认背景颜色设置为黑色 - 我认为它没有正确传递视图,但事实证明这正是它应该做的。有没有办法让它变得清晰,以便我想写给它的内容显示出来?或者如果我向视图控制器添加表格,内容会自动出现在上面吗?
    • 对于清除颜色设置背景颜色为[UIColor clearColor],如果添加tableView,内容不会出现,它将显示默认的单元格行,这些行只会显示为小水平线。为了显示内容,您需要在 tableView 中的各个单元格在 cellForRowAtIndexPath 协议中实例化之后将该内容添加到它们。
    • 也想出了该问题的答案-如果我将其设置为 clear 将不会显示任何内容,因此我在库本身中将其设置为白色。现在我需要将数据放到视图控制器上 >.>
    猜你喜欢
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    相关资源
    最近更新 更多