我有一個視圖控制器崩潰時,在導航視圖控制器中使用後退按鈕的問題。detailViewController崩潰dealloc由於屬性被釋放使用弧
在主表視圖控制器,我推翻爲賽格瑞像這樣製備:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"getHostedZoneSegue"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
GetHostedZoneViewController *detailViewController = [segue destinationViewController];
NSLog(@"setting zone ID");
detailViewController.zoneID = [hostedZonesListID objectAtIndex:selectedRowIndex.row];
}
}
GetHostedViewController有一個屬性了zoneid宣稱:
@interface GetHostedZoneViewController : UIViewController
{
NSString *zoneID;
}
@property (nonatomic, copy) NSString *zoneID;
在viewDidLoad中
我執行該調用的方法中的框架(對框架的調用發生在GCD異步塊中,並且框架不使用ARC):
Route53GetHostedZoneRequest *request =
[[Route53GetHostedZoneRequest alloc] initWithHostedZoneID:self.zoneID];
框架做它的事,像這樣: .H:
@interface Route53GetHostedZoneRequest : AmazonServiceRequestConfig
{
NSString *hostedZoneID;
}
@property (nonatomic, copy) NSString *hostedZoneID;
.M:
@synthesize hostedZoneID;
-(id)initWithHostedZoneID:(NSString *)theHostedZoneID
{
if (self = [self init]) {
hostedZoneID = theHostedZoneID;
}
return self;
}
在應用程序下一次調用是一個不同的方法在框架另一個類使用先前調用的結果:
Route53GetHostedZoneResponse *response = [[AmazonClientManager r53] getHostedZone:request];
完成此操作後,請求和響應都會釋放(如預期的那樣),第奇怪的是,當請求被釋放時,它也釋放zoneID。使用儀器我已經追蹤違規發佈:
[hostedZoneID release];
在Route53GetHostedZoneRequest.m的dealloc方法。
當返回到主控制器並釋放應用程序後,GetHostedZoneViewController被釋放時會導致殭屍。
如果我設置
detailViewController.zoneID = @"somestring";
的應用程序不會不管我多少次來回走崩潰。
任何人都可以解釋爲什麼這是崩潰,也許給我一些指導如何解決它?我真的不明白,爲什麼在了zoneid由[hostedZoneID發佈]發佈
在我看來,你是不是在viewDidLoad中初始化你的區域ID。不清楚,因爲你沒有告訴我們它是什麼。 – 2013-07-15 22:24:11
我相信它在主視圖控制器中的prepareForSegue中初始化,這似乎是接受的方式。 @Wain釘了這個問題,雖然......謝謝! – entr04y