2012-06-09 86 views
1

我有一個按鈕,在.h文件中IBAction爲,按鈕,相機

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

而且在我的.m文件中聲明我的界面我有:

-(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]; 
} 

但我有此錯誤:

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

有人可以幫我嗎?我不明白什麼是錯誤。 感謝

+0

有看看這個[鏈接](http://stackoverflow.com/questions/601074/objective-c-message-sent-to-deallocated-instance-0x5633b0)。 –

+0

好吧,我插入..我見過的方法viewDidLoad運行2次...爲什麼? – PsyKoWebMari

+0

現在我有: '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:]:發送到釋放實例的消息0x7dac3f0' – PsyKoWebMari

回答

0

按照從烏爾最後的評論代碼,

-(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]; 
} 

我可以建議你以下。 如果你看一下UIViewController類引用文件,你會發現下面的註釋

presentModalViewController:animated: 

呈現由給定的視圖控制器到用戶管理的模式的看法。 (棄用,使用presentViewController:animated:completion:代替。)

所以我建議你使用presentViewController:animated:completion。我不認爲它與錯誤「消息發送到釋放實例」有關,但仍然檢查你是否可以解決你的問題。

而且我不知道爲什麼ü寫這行

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

如果你只是想顯示當前UINavigationControllerUserProfileVC那麼我會建議你刪除addNavigationController線&只寫

[self.navigationController presentViewController:details animated:YES completion:NULL]; 
+0

我在編輯時編輯了代碼,userprofilevc的工作原理相同,但它實例化了2次。| (@「Annotation Click」);(id)發件人{ \t NSLog details = [[UserProfileVC alloc] initWithNibName:@「Details」bundle:nil]; details.Nome = note.title; details.coffeeObj = self.coffeeObj; [self presentViewController:details animated:YES completion:NULL]; \t }' 你可以看到已啓動2次 '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

+0

從哪裏得到這個日誌?你把哪個方法放在'NSLog'上? &你到底有什麼問題? –

+0

我已經在userprofilevc的viewDidLoad中插入了nslog ...問題從一開始就是一樣的...我的意思是用戶profilevc的雙重分配...實際上 – PsyKoWebMari