如何使用Objc的CAPSPageMenu源代码?

时间:2017-05-19 09:32:56

标签: ios objective-c

我正在使用目标C开发IOS项目。 我打算制作滑动标签页。 我从github找到了这个来源。 https://github.com/PageMenu/PageMenu

这是我使用CAPSPageMenu的源代码。 什么时候

@interface BusinessTabViewController ()
@property(nonatomic) CAPSPageMenu* pageMenu;
@end

@implementation BusinessTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableArray *controllerArray = [NSMutableArray array];
    UIViewController*controller = [[UIViewController alloc] initWithNibName:@"GongsiyingyeViewController" bundle:nil];
    controller.title  = @"Sample title";
    [controllerArray addObject:controller];
    NSDictionary *parameteres = @{CAPSPageMenuOptionMenuItemSeparatorWidth:@(4.3), CAPSPageMenuOptionUseMenuLikeSegmentedControl:@(YES), CAPSPageMenuOptionMenuItemSeparatorPercentageHeight:@(0.1)};
    _pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) options:parameteres];
    [self.view addSubview:_pageMenu.view];
}

仅显示白屏。 请帮忙。 感谢。

2 个答案:

答案 0 :(得分:0)

该错误与PageMenu无关,请注释注册推送通知的代码然后尝试。

在推送viewcontroller之前检查viewcontroller是否为nil。

CAPSPageMenu在我们的项目中运作良好。

答案 1 :(得分:0)

@interface BusinessTabViewController ()
@property(nonatomic) CAPSPageMenu* pageMenu;
@end

@implementation BusinessTabViewController


-(void) viewDidLayoutSubviews{
    NSMutableArray *controllerArray = [NSMutableArray array];
    UIViewController*controller = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    controller.title  = @"Sample title1";
    UIViewController*controller1 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    controller1.title  = @"Sample title2";
    UIViewController*controller2 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    controller2.title  = @"Sample title3";
    [controllerArray addObject:controller];
    [controllerArray addObject:controller1];
    [controllerArray addObject:controller2];

    NSDictionary *parameteres = @{
                                  CAPSPageMenuOptionMenuItemSeparatorWidth:@(4.3),
                                  CAPSPageMenuOptionUseMenuLikeSegmentedControl:@(YES),
                                  CAPSPageMenuOptionMenuItemSeparatorPercentageHeight:@(0.1),
                                  CAPSPageMenuOptionMenuHeight:@(40),
                                  CAPSPageMenuOptionMenuMargin:@(20),
                                  CAPSPageMenuOptionSelectionIndicatorHeight:@(2.0)

                                  };
    _pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) options:parameteres];
    [self.view addSubview:_pageMenu.view];

}

我使用viewDidLayoutSubviews()来获得准确的帧大小。 它工作正常。