我在空閒時間工作在ipad上,我碰到過一個小問題。在我uisplitview,如果我點擊一個細胞,它加載的圖片,我有另外兩個單元,每個單元有此代碼爲點擊從supreview中刪除,只有它存在
[self.icon1 removeFromSuperview];
時能正常工作,但去掉圖片。如果之後我點擊單元格與圖片...然後我單擊單元格2(和此刪除代碼運行)它正確地刪除圖片。但如果我點擊單元格3 ...則程序中斷(訪問不良,它指向removeFromSuperview)。而我認爲這是因爲圖標已被刪除。基本上說有沒有一個功能說「如果存在然後從superview中刪除」? 謝謝
if (([receivedRainObject isEqualToString:@"Facts"]) && (Track==100)) {
self.view.backgroundColor=[UIColor whiteColor];
// self.tvFacts=[[UITextView alloc]initWithFrame:CGRectMake(0, 150, 700, 500)];
[email protected]" Test";
[tvFacts setEditable:NO];
UIImage *acheivement1=[UIImage imageNamed:@"saychesse.png"];
[factBanner1 setImage:acheivement1];
UIImage *fbIcon= [UIImage imageNamed:@"facebook.png"];
fbIcon1 = [UIButton buttonWithType:UIButtonTypeCustom];
fbIcon1.frame = CGRectMake(580.0, 305.0, 35.0, 35.0);
fbIcon1.tag=TAG_BUTTON_ONE;
[fbIcon1 addTarget:self action:@selector(authButtonAction) forControlEvents:UIControlEventTouchUpInside];
[fbIcon1 setBackgroundImage:fbIcon forState:UIControlStateNormal];
UIImage *twIcon= [UIImage imageNamed:@"twitter.png"];
twIcon1 = [UIButton buttonWithType:UIButtonTypeCustom];
twIcon1.frame = CGRectMake(530.0, 305.0, 35.0, 35.0);
[twIcon1 addTarget:self action:@selector(tweetTapped) forControlEvents:UIControlEventTouchUpInside];
[twIcon1 setBackgroundImage:twIcon forState:UIControlStateNormal];
[self.imgClassification removeFromSuperview];
[self.Image removeFromSuperview];
[self.lblSel removeFromSuperview];
[self.tvDescrip removeFromSuperview];
[self.tvName removeFromSuperview];
[self.tvDiet removeFromSuperview];
[self.navigationController popViewControllerAnimated:NO];
[self.lblPictureAnnotation removeFromSuperview];
[self.lbllife removeFromSuperview];
[self.tvGestation removeFromSuperview];
[self.view addSubview:self.tvFacts];
[self.view addSubview:factBanner1];
[self.view addSubview:fbIcon1];
[self.view addSubview:twIcon1];
[self.view setNeedsDisplay];
}
// Life-Span
if (([receivedRainObject isEqualToString:@"Life Span"]) && (Track==100)) {
self.view.backgroundColor=[UIColor whiteColor];
// self.lbllife=[[UILabel alloc]initWithFrame:CGRectMake(0, 150, 700, 500)];
[email protected]"The";
[lbllife setEditable:NO];
[self.factBanner1 removeFromSuperview];
[self.fbIcon1 removeFromSuperview];
[self.twIcon1 removeFromSuperview];
[self.factBanner2 removeFromSuperview];
[self.fbIcon2 removeFromSuperview];
[self.twIcon2 removeFromSuperview];
[self.imgClassification removeFromSuperview];
[self.Image removeFromSuperview];
[self.lblSel removeFromSuperview];
[self.tvDescrip removeFromSuperview];
[self.tvName removeFromSuperview];
[self.tvDiet removeFromSuperview];
[self.navigationController popViewControllerAnimated:NO];
[self.tvFacts removeFromSuperview];
[self.lblPictureAnnotation removeFromSuperview];
[self.tvGestation removeFromSuperview];
[self.factBanner1 removeFromSuperview];
[self.view addSubview:self.lbllife];
[self.view setNeedsDisplay];
}
你確定它是子視圖的問題,還是它的根'self'被釋放? – CodaFi 2013-03-17 05:20:57
一,這甚至與Xcode沒有遠程相關。二,展示你的代碼。更有可能是你有內存管理錯誤,你的懷疑是不正確的。 – 2013-03-17 05:21:02
這更像是內存問題。你有一個對一個釋放對象的引用。嘗試啓用NSZombie,並參見 – 2013-03-17 05:27:14