我目前正在創建一本iPad的書。不幸的是,由於這是我的第一個iPad項目,我正以非常規的方式進行編碼。如何切換到另一個XIB並完成以前的XIB?
這是一本20頁的書,我有20個XIB。在每個XIB上,我都會調用下一個XIB,但是我擔心的是當前的XIB沒有被卸載,仍然佔用內存。當我在第10頁左右時,應用程序將因didReceiveMemoryWarning
而崩潰。
我切換使用2種不同的方法的意見(我不知道哪一個會更適合我的目的):
#METHOD 1
-(IBAction)NextPage:(id)sender
{
nextPage = [[NextPage alloc] initWithNibName:@"NextPage" bundle:nil];
[self.view addSubview:nextPage.view];
[self presentModalViewController:nextPage animated:YES];
[self.view release]; // this was added to hopefully release the current view.
}
#METHOD 2
-(IBAction)NextPage:(id)sender
{
NextPage *nextpage = [[[NextPage alloc] init] autorelease];
[self presentModalViewController:nextpage animated:YES];
}
每個視圖都有按鈕之類的東西,但我想確保我完全擦除他們從每個頁面調用內存。
我用dealloc
嘗試刪除視圖,但是當我檢查內存泄漏並在頁面之間來回切換時,內存會爬起來。
- (void)dealloc {
[view release]; // don't know which is which
[self.view release]; // is this correct?
[super dealloc];
}
任何幫助表示讚賞!提前致謝。
我該如何做到這一點? – namkyu