【问题标题】:self.revealViewController.panGestureRecognizer showing null in iOS SWRevealViewControllerself.revealViewController.panGestureRecognizer 在 iOS SWRevealViewController 中显示 null
【发布时间】:2015-11-15 01:11:24
【问题描述】:

我不想在我的应用程序中使用 SWRevealViewController,因为我按照给定的链接“https://www.youtube.com/watch?v=5SUV1YY2yxQ”执行步骤。

但是我的应用程序在这一行崩溃了

[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

编译器显示以下错误

由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'*** -[__NSArrayM insertObject:atIndex:]: 对象不能为 nil'。

请检查我的故事板设计

下面是我想要打开显示视图控制器.h 文件的蓝色背景视图代码

#import <UIKit/UIKit.h>
 #import "SWRevealViewController.h"

@interface DashboardSixOptionViewController : UIViewController 
{

    SWRevealViewController *revealViewController;

}

@property (nonatomic,retain) SWRevealViewController *revealViewController;
@end

.m 文件

@interface DashboardSixOptionViewController ()

@end

@implementation DashboardSixOptionViewController
@synthesize revealViewController = _revealViewController;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"gesture desc::%@",self.revealViewController.panGestureRecognizer);


    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
-(void)configureView
{
 [self.navigationController.navigationBar setTintColor:[UIColor orangeColor]];

    CGRect dashboardNavFrame = self.navigationController.navigationBar.bounds;
//    dashboardNavFrame.size.height += 5;

    self.toolBar = [[UIToolbar alloc] initWithFrame:dashboardNavFrame];

    [self.toolBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

    [self.toolBar setTintColor:[UIColor redColor]];


    //disable any back btn
    self.toolBar.clearsContextBeforeDrawing = NO;
    self.toolBar.clipsToBounds = NO;
    [self.toolBar setTag:700];

    NSMutableArray *buttons = [[NSMutableArray alloc] init];


    UIImage *imgOption;

    imgOption = [UIImage imageNamed:@"imgOptionsIOS7.png"];

    UIButton *aOptionButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [aOptionButton setEnabled:NO];
    aOptionButton.frame = CGRectMake(0, 0, imgOption.size.width, imgOption.size.height);
    [aOptionButton setImage:imgOption forState:UIControlStateNormal];
//    [aOptionButton addTarget:self action:@selector(showLeftMenu:) forControlEvents:UIControlEventTouchUpInside];
    [aOptionButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];


    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:aOptionButton];
    [btn setTarget:self.revealViewController];
    [btn setAction:@selector(revealToggle:)];
    [buttons addObject:btn];
  [self.toolBar setItems:buttons animated:YES];

    [self.navigationController.navigationBar addSubview:self.toolBar];

}

从视图控制器 DashboardSixOptionView 视图推送下面是我的代码

DashboardSixOptionView  = [mainStoryboard instantiateViewControllerWithIdentifier:@"DashboardStoryBoardWithSixOption"];
    DashboardSixOptionView.arrTableViewHreaders = self.arrForMenuOption;
    [self.navigationController pushViewController:DashboardSixOptionView animated:YES];

请帮我看看我为什么会崩溃。

提前致谢 普里扬卡

【问题讨论】:

    标签: ios objective-c swrevealviewcontroller


    【解决方案1】:

    我猜self.revealViewController.panGestureRecognizernil,因为您为 SWRevealViewController 创建了一个属性,但没有在viewDidLoad 中分配任何值。

    您是否在 Storyboard 中正确设置了所有类?

    另外,你为什么要为你的 SWRevealViewController 使用@synthesize 和一个类变量?没有必要再这样做了。

    我建议您查看this great tutorial 的 SWRevealViewController。

    【讨论】:

    • 嗨,感谢重播。我刚刚尝试创建属性和@synthesize ..点击此链接“appcoda.com/ios-programming-sidebar-navigation-menu”但仍然遇到同样的错误。
    • 不,我的意思是你不再需要使用合成。只需使用该属性。只需删除这些行:'@synthesize revealViewController = _revealViewController;`(在.m 文件中){ SWRevealViewController *revealViewController; }(在.h 文件中)再次检查教程并检查您在情节提要中设置了哪些类。在 Identity Inspector 中查找它(右侧面板,从左侧开始的第三个图标)。
    【解决方案2】:

    不要在DashboardSixOptionViewController.hDashboardSixOptionViewController.m 文件中为SWRevealViewController 创建新对象。取而代之的是,使用在 SWRevealViewController 类中创建的相同对象。

    DashboardSixOptionViewController.m 类

    #import "SWRevealViewController.h"
    -(void)viewDidLoad{
    _barButton.target = self.revealViewController;
    _barButton.action = @selector(revealToggle:);
    [self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];
    }
    

    【讨论】:

    • 创建了带有条形按钮的工具栏,并将收费栏放在导航栏 UIButton *aOptionButton = [UIButton buttonWithType:UIButtonTypeCustom]; aOptionButton.frame = CGRectMake(0, 0, imgOption.size.width, imgOption.size.height); [aOptionButton setImage:imgOption forState:UIControlStateNormal]; [aOptionButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
    • UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:aOptionButton]; [btn setTarget:self.revealViewController]; [btn setAction:@selector(revealToggle:)]; [按钮添加对象:btn]; [self.toolBar setItems:按钮动画:YES]; [self.navigationController.navigationBar addSubview:self.toolBar];
    • 从你的故事板中,注意到 LeftMenuList 是 UIViewController 的子类。这应该是 UITableViewController 的子类。试试这个
    • 嗨,Daya Kevin,我尝试过使用表格视图的子类,但我仍然从下面的行 [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer] 得到 self.revealViewController.panGestureRecognize = nil;跨度>
    【解决方案3】:

    我也遇到了同样的问题!! 如果你想连接到菜单视图控制器,你必须通过swrevealviewcontrtoller 连接它,所以再次检查你的 segues,这解决了我的问题,我使用了。

    [self.revealviewcontroller pangesturerecogonizer];
    

    代替

    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    

    【讨论】:

      猜你喜欢
      • 2015-03-27
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 2013-10-14
      • 2017-12-31
      相关资源
      最近更新 更多