1

So I'm trying to open a view within an app from a button press and I'm shown the following error:

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

The action for the button press is:

-(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" );

            }];
        }

    }
}
}

Additionally I have tried the two lines you can see that have been commented out:

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

These don't make any difference unfortunately. I'm new to IOS development and not sure where to go from here.

Additionally there is a method elsewhere in the app called copyWithZone but even if i remove this entirely I still get the error with the reference.

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

return copy;
}
jampez77
  • 5,012
  • 7
  • 32
  • 52
  • `ontracDirectionsMapViewController` is on storyboard? – Ketan Parmar Apr 14 '16 at 09:54
  • @Lion Yes it is, i think – jampez77 Apr 14 '16 at 10:01
  • One answer is there. this is seems to right. do like that. – Ketan Parmar Apr 14 '16 at 10:33
  • AFAIK: the `copyWithZone` is a protocol method for [copying]( https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSCopying_Protocol/) i.e. you have a property which is something like this `@property ( someOther attributes, copy)`...But you can't just say that, the object that you intend to copy must follow/conform/adapt `NSCopying` protocol, if not it will give you such an error. See [**this**](http://stackoverflow.com/questions/4089238/implementing-nscopying) as well – mfaani Apr 14 '16 at 10:39
  • Possible duplicate of [-\[MyClassName copyWithZone:\] unrecognized selector sent to instance](http://stackoverflow.com/questions/11391835/myclassname-copywithzone-unrecognized-selector-sent-to-instance) – mfaani Apr 14 '16 at 11:08

2 Answers2

1

If you are using storyboards, set the storyboard identifier to your ontracTableMasterViewController and instantiate it as follows:

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

Please check the attached image to set YOUR_IDENTIFIER in storyboard. Hope this helps!

enter image description here

Dinesh
  • 1,137
  • 9
  • 14
0

OK so I lucked into an answer! What I did was change the following line @property (copy, nonatomic) IBOutlet UINavigationBar *directionsNavigationBar; in ontracMapViewController.h to @property (strong, nonatomic) IBOutlet UINavigationBar *directionsNavigationBar;

This then produce the following error, preferredInterfaceOrientationForPresentation must return a supported interface orientation! which I solved by adding the code below:

-(BOOL)shouldAutorotate
{
   return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return UIInterfaceOrientationLandscapeRight;
}

Like i said in the question I'm new to IOS dev so not sure what was happening in the first place but this seems to be working fine now. Thanks to everyone for the help though.

jampez77
  • 5,012
  • 7
  • 32
  • 52