【问题标题】:Xcode - presentViewController NSInvalidArgumentException: unrecognized selector sent to instanceXcode - presentViewController NSInvalidArgumentException:无法识别的选择器发送到实例
【发布时间】:2016-08-05 18:22:13
【问题描述】:

所以我试图通过按下按钮在应用程序中打开视图,但显示以下错误:

'NSInvalidArgumentException', reason: '-[UINavigationBar copyWithZone:]: unrecognized selector sent to instance 0x1e56aa10'

按钮按下的动作是:

-(IBAction)launchDirections:(id)sender
{
@autoreleasepool {

if([CLLocationManager locationServicesEnabled]){



        if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied
            || [CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined
            || [CLLocationManager authorizationStatus]==kCLAuthorizationStatusRestricted   ){

            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"App Permission Denied"
                                           message:@"To re-enable, please go to Settings and turn on Location Service for this app."
                                          delegate:nil
                                 cancelButtonTitle:@"OK"
                                 otherButtonTitles:nil];
            [alert show];
        }else{
            NSLog(@"Location Services Enabled");
            ontracDirectionsMapViewController *directions = [[ontracDirectionsMapViewController alloc] init];
            directions.start = userLocation;
            directions.end =selectedPointLocation;

            //[self presentViewController:directions animated:NO completion:nil];
            //[self.navigationController pushViewController:directions animated:YES];

            [ self presentViewController : directions animated : YES completion : ^ {

                NSLog ( @ "hello" );

            }];
        }

    }
}
}

此外,我已经尝试了您可以看到已被注释掉的两行:

//[self presentViewController:directions animated:NO completion:nil];
//[self.navigationController pushViewController:directions animated:YES];

不幸的是,这些没有任何区别。我是 IOS 开发新手,不知道从哪里开始。

此外,应用程序中的其他地方还有一个名为 copyWithZone 的方法,但即使我完全删除它,我仍然会收到参考错误。

-(id)copyWithZone:(NSZone *)zone
{
ontracTableMasterViewController *copy = [[ontracTableMasterViewController alloc] init];
copy.cookieValue = self.cookieValue;
copy.dataObject = self.dataObject;

return copy;
}

【问题讨论】:

标签: ios objective-c xcode


【解决方案1】:

如果您使用情节提要,请将情节提要标识符设置为您的 ontracTableMasterViewController 并按如下方式对其进行实例化:

    ontracTableMasterViewController *oVC = (ontracTableMasterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"YOUR_IDENTIFIER"];
    oVC.start = userLocation;
    oVC.end = selectedPointLocation;
    [self presentViewController:oVC animated:YES completion:nil];

请检查所附图片以在情节提要中设置 YOUR_IDENTIFIER。 希望这会有所帮助!

【讨论】:

  • 我没有设置捆绑 ID 的选项:/
  • 你好@jampez77 你在用什么?故事板或 .xib 或纯粹以编程方式创建 UI?
【解决方案2】:

好的,所以我很幸运地得到了答案!我所做的是将ontracMapViewController.h中的以下行@property (copy, nonatomic) IBOutlet UINavigationBar *directionsNavigationBar;更改为@property (strong, nonatomic) IBOutlet UINavigationBar *directionsNavigationBar;

这会产生以下错误,preferredInterfaceOrientationForPresentation must return a supported interface orientation! 我通过添加以下代码解决了这个问题:

-(BOOL)shouldAutorotate
{
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return UIInterfaceOrientationLandscapeRight;
}

就像我在问题中所说的那样,我是 IOS 开发人员的新手,所以不确定首先发生了什么,但这似乎现在工作正常。不过感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2013-12-26
    • 2012-07-16
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    • 2015-08-02
    相关资源
    最近更新 更多