NSCFString _forgetDependentConstraint无法识别的选择器发送到实例

时间:2012-12-09 09:14:07

标签: iphone objective-c

在我的应用程序中,当我单击RightBarButtonItem时,它会推送另一个视图控制器,但它显示以下错误。

-[__NSCFString _forgetDependentConstraint:]: unrecognized selector sent to instance 0x74c5960

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _forgetDependentConstraint:]: unrecognized selector sent to instance 0x74c5960'

我不知道我做错了什么。

但在该视图控制器中我只将此代码放在viewDidLoad第二视图控制器

            [self.navigationController setNavigationBarHidden:TRUE animated:YES]; 




        first view controller contains the following code

        - (void)viewDidLoad
        {
            [super viewDidLoad];

            [self.navigationController setNavigationBarHidden:TRUE animated:YES];
        baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];

            UINavigationBar *navBar1 = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
            UINavigationItem *navItem1 = [[UINavigationItem alloc] initWithTitle:@""];
            [navBar1 pushNavigationItem:navItem1 animated:NO];
            UIBarButtonItem *menuButton1 = [[UIBarButtonItem alloc] initWithTitle:@""
                                                                            style:UIBarButtonItemStyleBordered
                                                                           target:self
                                                                           action:@selector(toggleMenu1)];
            navItem1.leftBarButtonItem = menuButton1;
            [baseView.self addSubview:navBar1];
            UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scr2.png"]];
            [baseView.self addSubview:backgroundImage];

            UIPanGestureRecognizer *pancontrol = [[UIPanGestureRecognizer alloc]
                                           initWithTarget:self action:@selector(panLayer:)];
            [self.view addGestureRecognizer:pancontrol];

            topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];

            UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
            UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@""];
            [navBar pushNavigationItem:navItem animated:NO];
            UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithTitle:@"Menu"
                                                 `enter code here`                         style:UIBarButtonItemStyleBordered                                                                  target:self
                                                                          action:@selector(toggleMenu)];
            navItem.leftBarButtonItem = menuButton;
            UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Add"
                                                                          style:UIBarButtonItemStyleBordered
                                                                         target:self
                                                                         action:@selector(toggleAdd)];
            navItem.rightBarButtonItem = addButton;
            [topView.self addSubview:navBar];
            backgroundImage1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"notebookbg.png"]];
            [topView.self addSubview:backgroundImage1];
            [baseView.self addSubview:topView];
            [self.view addSubview:baseView];
                }

这些是我的代码。

如何从第一个视图控制器移动到下一个视图控制器。

2 个答案:

答案 0 :(得分:1)

听起来像是你没有正确地将实际NSString分配给第一个或第二个视图控制器的标题或文本属性之一。

要找出问题发生的位置,请执行以下操作: - 在NSString上实现一个调试类,并添加一个只包含断点的_forgetDependentConstraint:方法。 - 当执行中断此方法时,请检查调用堆栈以查看其确切中断的位置 - 还检查方法中的self并检查字符串是罪魁祸首。

听起来好像你在视图层次结构中的某处有一个NSString而不是UIView。 UIView子类具有此_forgetDependentConstraint:方法,但字符串不具有。

答案 1 :(得分:1)

问题似乎与AddNewNote类有关。正如Cocoanetics建议的那样,在NSString上创建一个类别并在类别中实现_forgetDependentConstraint :.在#import文件

中为新类别标题添加.PCH