2012-11-22 66 views
0

我有一個應用程序在那裏我從攝像機捕獲圖像,並將其設置爲按鈕。iPhone應用程序崩潰與NSCFType setImage:forState

所以,與使用按鈕從照相機和抽頭捕獲圖像,我的應用程序崩潰後[NSCFType setImage:forstate]無法識別的實例

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [picker dismissModalViewControllerAnimated:YES]; 

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    UIImage *resizeImage = [image imageWithImage:image scaledToSize:CGSizeMake(320, 480)];  

    //convert the selected image to NSData 
    toShowFullImage = UIImageJPEGRepresentation(resizeImage, 0.8); 

    //retain it for further use 
    [toShowFullImage retain]; 

    //set the selected image to button 

    UIImage *newimage=[image imageScaleAndCropToMaxSize:CGSizeMake(75, 75)]; 

    [button setImage:newimage forState:UIControlStateNormal]; 
} 

在IOS 6.0.1發生與中止陷阱6錯誤這個崩潰

+0

請發表你設置圖像.. –

+0

@ParasJoshi代碼:我張貼代碼檢查我的編輯。 –

+0

@ user1530787:您是如何將按鈕添加到您的視圖的?請張貼該代碼。 –

回答

0

我認爲問題是,當你設置按鈕,它已經發布的背景圖像。

這個問題的可能途徑:

  1. 當您添加的按鈕視圖,你叫[button release];
  2. 您創建使用工廠方法按鈕像buttonWithType:

可能解決方案:

  1. 設置爲查看後不要調用釋放。
  2. 只需使用按鈕創建按鈕buttonWithType:
  3. 使用標籤設置圖像。

當您添加的按鈕設置標籤,如:

button.tag = 7; 
[self.view addSubview:button]; 

並設置喜歡的圖像:

[[self.view viewWithTag:7] setImage:newimage forState:UIControlStateNormal]; 
+0

我按照以下方式添加了按鈕:'UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(65.0,10.0,75.0,75.0); [button addTarget:self action:@selector(getFullImage)forControlEvents:UIControlEventTouchDown]; ',我不會釋放任何按鈕。這是否導致崩潰?請幫助我,我是iOS開發新手。 –

+0

使用上面的代碼。添加標籤到按鈕。當您設置圖像時,請使用該標籤參考按鈕。 –

+0

仍然有問題? –

0

覈對一下你的Alloc按鈕或沒有,也給人以出口基準或不前也設置圖像的任何地方你relese這個按鈕,則這種類型的錯誤發生,以便檢查這種流動隊友..而且也看到這個代碼可以這也很容易使用你..

代替newimage ..直接設置圖像按鈕的背景例如..

[button setBackgroundImage:image forState:UIControlStateNormal];