开发者

[NSManagedObject isEqualToString:]: unrecognized selector sent to instance 0x454a590'

开发者 https://www.devze.com 2023-01-08 17:20 出处:网络
I\'m getting the above error and have no idea where its happening. Is there any way to debug it. I\'ve put in some breaks points already buts its not abending its not abending those areas.

I'm getting the above error and have no idea where its happening. Is there any way to debug it. I've put in some breaks points already buts its not abending its not abending those areas.

Code below:

    -(void)viewDidLoad 
    { 
     if (managedObjectContext == nil) 
     { 
            managedObjectContext = [(NewWorkoutViewController *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
            NSLog(@"After managedObjectContext: %@",  managedObjectContext);
     }

     //Setup PickerView values.  
     [UIView beginAnimations:nil context:nil];
     [UIView setAnimationDuration:1.0];
     CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
     pickerView.transform = transform;
     [UIView commitAnimations];
     // When the view loads, run this action.
     [super viewDidLoad]; // This NEEDS to be here or the application will not work!
     route.delegate = self;

     //Initialise variable.
     counterInt = 0;
    } 


    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
     UITouch *touch;
     touch=[touches anyObject];
     CGPoint point=[touch locationInView:self.view];

     if (CGRectContainsPoint([route frame],point))
     {
      [self routePickerShow];
     }

     if (CGRectContainsPoint([activity frame],point))
     {
      [self activityPickerShow];
     }

     if (CGRectContainsPoint([intensity frame],point))
     {
      [self intensityPickerShow];
     }
    }


-(IBAction)routePickerShow
{  
 NSFetchRequest *request = [[NSFetchRequest alloc] init];

 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Route" inManagedObjectContext:managedObjectContext];
 [request setEntity:entity];

 NSError *error = nil;
 NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];

 // Check for errors from the FetchRequest
 if (nil == results || nil != error)
  NSLog(@"Error getting results : %@", error);

 routeArray = [results mutableCopy];
 [request release];

 int arrayItemQuantity = [routeArray count];
 NSLog(@"Array Quantity: %d", arrayItemQuantity);
 int i;

    for (i = 0; i < arrayItemQuantity; i++)
 {  
  NSLog(@"Element %i: %@", i, [[routeArray objectAtIndex:i] valueForKey:@"route_name"]);
  NSLog(@"Element %i: %@", i, [[routeArray objectAtIndex:i] valueForKey:@"route_id"]);
 }

 // Initialise PickerView details.
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:0.5];
 CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 200);
 pickerView.transform = transform;
 [self.view addSubview:pickerView];
 [UIView commitAnimations]; 
}


-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)routePicker
{
 return 1;
}


-(NSInteger)pickerView:(UIPickerView *)routePicker numberOfRowsInComponent:(NSInteger)component
{
 return [routeArray count];
}


-(NSString *)pickerView:(UIPickerView *)routePicker titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
 return [routeArray objec开发者_开发知识库tAtIndex:row];
}


-(void)pickerView:(UIPickerView *)routePicker didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
 route.text = [[routeArray objectAtIndex:row] valueForKey:@"route_name"];
 mapID = [[routeArray objectAtIndex:row] valueForKey:@"route_id"];
 NSLog(@"Map ID NW: %@", mapID);

 //activity.text = [list objectAtIndex:row];
 //intensity.text = [list objectAtIndex:row];
}

All I know is that its not getting as far a the method pickerView, it abends before this.


Your specific error is that you have a string that you are trying to set to a Core Data object. Is route_id an object or a string? Is mapID a string? It could be this line:

NSLog(@"Element %i: %@", i, [[routeArray objectAtIndex:i] valueForKey:@"route_id"]);

Also, you might want to add a breakpoint to catch uncaught exceptions. Open the breakpoints window. Select the Global Breakpoints group so you only have to do this once and it will be in all projects. Add objc_exception_throw to the break points and you will catch all exceptions before they crash your code. Also, enable NSZombies in your debug code. See here and here for some info.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号