A->B subview(viewcontroller.view)-->Presentmodalviewcontroller(C)
我的第二页:(B)代码是
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
[currentElement release];
currentElement = [elementName copy];
if ([elementName isEqualToString:@"result"] ) {
Prodid = [[NSMutableString alloc] init];
}
} login.prodid = Prodid;
login.categid=self.categid;
UINavigationController *navCtrl= [UINavigationController alloc initWithRootViewController:login];
自呈现presentModalViewController:navCtrl动画:是;
登录发布;
navCtrl释放;
原产释放;
}
在我的下一页(C)中有一个取消按钮
-(void) cancel
{
[self dismissModalViewControllerAnimated:YES];
} 如果我单击cancel按钮,应用程序崩溃,.I,检查nszombie,并找到过释放的对象(Prodid)。如果我删除Prodid,应用程序可以工作,但是Prodid.How中的漏洞,我能解决这个问题。
发布于 2011-09-01 13:13:29
if ([elementName isEqualToString:@"result"] ) {
Prodid = [[NSMutableString alloc] init];
}
}
[Prodid release];在发布之前,您并不总是分配Prodid。将代码更改为只有在分配代码时才释放它。也许吧
if ([elementName isEqualToString:@"result"] ) {
Prodid = [[NSMutableString alloc] init];
}
else
{
Prodid = nil;
}
[Prodid release];
Prodid = nil;这将有效,因为发送给零的消息不会做任何事情。
发布于 2011-09-01 12:55:48
您应该在调试器中模仿应用程序崩溃的部分代码。根据您的描述,我假设您试图将dismissModalViewController消息发送给navCtl,而不是发送给它的所有者。
[self.parentViewController dismissModalViewControllerAnimated:YES];发布于 2011-09-01 13:01:49
如果您查看iOS文档,您将发现模态视图控制器拒绝自己(如果可能的话)是不好的形式。正确的形式是您的第一个视图控制器执行解散。
可以这样想:呈现一个模态视图控制器会给出某种所有权。您的第二个视图控制器属于第一个视图控制器,什么都不拥有。因此,由于第二个视图控制器没有模态视图控制器,所以调用‘SelfunissModalViewController动画:YES’失败。
通常,在这种情况下,我在“基本”视图控制器和模态视图控制器之间建立了某种委托关系。在设置“基本”视图控制器时,还可以将目标添加到“取消”按钮中。
也许是这样的:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
[currentElement release];
currentElement = [elementName copy];
if ([elementName isEqualToString:@"result"] ) {
Prodid = [[NSMutableString alloc] init];
}
page *login=[[page alloc]init];
login.prodid = Prodid;
login.categid=self.categid;
UINavigationController *navCtrl= [[UINavigationController alloc] initWithRootViewController:login];
[[login cancelButton] addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
[self presentModalViewController:navCtrl animated:YES];
[login release];
[navCtrl release];
}
-(void) dealloc
{
[Prodid release];
}
// Put this method in the "base" view controller, NOT the modal one
-(void) cancel
{
[self dismissModalViewControllerAnimated:YES];
} https://stackoverflow.com/questions/7270427
复制相似问题