1

I have a button in my interface declared in .h file

@interface UserProfileVC : UIViewController <UIImagePickerControllerDelegate>{
    IBOutlet UIButton *camera;
}
@property (nonatomic,retain) IBOutlet UIButton *camera;
-(IBAction)cameraPress:(id)sender;

And in my .m file i have:

-(IBAction)cameraPress:(id)sender{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//  [picker setDelegate:self];
    [picker setAllowsEditing:YES];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

But I have this error:

*** -[UserProfileVC performSelector:withObject:withObject:]: message sent to deallocated instance 0x7bc2a40

Can someone help me? I can't understand what is the mistake. Thanks

PsyKoWebMari
  • 415
  • 5
  • 11
  • have a look at this [link](http://stackoverflow.com/questions/601074/objective-c-message-sent-to-deallocated-instance-0x5633b0). – hp iOS Coder Jun 09 '12 at 11:54
  • Ok I inserted.. and I have seen that method viewDidLoad run 2 times ... Why? – PsyKoWebMari Jun 09 '12 at 12:24
  • Now I have: `2012-06-09 14:41:08.556 SQL[612:11603] INIT 0x7dac3f0 2012-06-09 14:41:08.557 SQL[612:11603] INIT 0x7da87c0 2012-06-09 14:41:10.475 SQL[612:11603] *** -[UserProfileVC performSelector:withObject:withObject:]: message sent to deallocated instance 0x7dac3f0 ` – PsyKoWebMari Jun 09 '12 at 12:42
  • The code shown in ur question is perfect. I want u to show the lines of code u wrote for calling the method `-[UserProfileVC performSelector:withObject:withObject:]` Edit ur question accordingly. – hp iOS Coder Jun 11 '12 at 05:59
  • I call the class UserProfileVC with this method... `-(void)showDetails:(id)sender{ NSLog(@"Annotation Click"); details= [[UserProfileVC alloc] initWithNibName: @"Details" bundle:nil ]; details.Nome=note.title; addNavigationController = [[UINavigationController alloc] initWithRootViewController:details]; [self.navigationController presentModalViewController:addNavigationController animated:YES]; } ` – PsyKoWebMari Jun 12 '12 at 14:26

1 Answers1

0

As per the code from ur last comment,

-(void)showDetails:(id)sender{ 
NSLog(@"Annotation Click"); 
details= [[UserProfileVC alloc] initWithNibName: @"Details" bundle:nil ]; 
details.Nome=note.title; 
addNavigationController = [[UINavigationController alloc] initWithRootViewController:details]; 
[self.navigationController presentModalViewController:addNavigationController animated:YES]; 
}

I can suggest you following. If you look at the UIViewController class reference document, you will find below notes

presentModalViewController:animated:

Presents a modal view managed by the given view controller to the user. (Deprecated. Use presentViewController:animated:completion: instead.)

So I would suggest you to use presentViewController:animated:completion. I dont find it relevant to error "message sent to deallocated instance" but still check if u could solve your problem.

Also I dont know Why u wrote this line

addNavigationController = [[UINavigationController alloc] initWithRootViewController:details]; 

If you simply want to show UserProfileVC in the current UINavigationController then I would suggest you to remove addNavigationController line & write only

[self.navigationController presentViewController:details animated:YES completion:NULL];
hp iOS Coder
  • 3,230
  • 2
  • 23
  • 39
  • I edited the code as you write, the userprofilevc works the same but it is instanced 2 times.| `-(void)showDetails:(id)sender{ NSLog(@"Annotation Click"); details= [[UserProfileVC alloc] initWithNibName: @"Details" bundle:nil ]; details.Nome=note.title; details.coffeeObj=self.coffeeObj; [self presentViewController:details animated:YES completion:NULL]; }` As you can see was initiated 2 times `2012-06-13 11:41:28.146 SQL[11463:11903] INIT 0x4e0b5f40 2012-06-13 11:41:28.156 SQL[11463:11903] INIT 0x4dcfbf40` – PsyKoWebMari Jun 13 '12 at 09:43
  • From where u got this log? In which method u put `NSLog`? & whats exactly the problem u have now? – hp iOS Coder Jun 13 '12 at 10:26
  • I have inserted nslog in the viewDidLoad of userprofilevc... The problem was the same from the beginning... I mean the double allocation of user profilevc... In fact – PsyKoWebMari Jun 13 '12 at 18:25
  • I have inserted nslog in the viewDidLoad of userprofilevc... The problem was the same from the beginning... I mean the double allocation of user profilevc... In fact these 2 Nslog indicate the code of two classes – PsyKoWebMari Jun 13 '12 at 18:34