我有这种情况,我想从视图中弹出并返回原始视图
按下按钮后,应用程序崩溃,控制台显示EXC_BAD_ACCESS
我在启用了僵尸的乐器中运行它,这就是我得到的:link to image
如图所示,对同一个对象调用dealloc两次。
工具指向NSMutableArray
,其中包含NSStrings
。
任何人都可以帮我解决这个问题...... 谢谢。
ps:this question中提供的解决方案无法解决问题。
编辑: 数组中填充了从xml文件解析的数据。
-(void) grabData{
listOfNames=[[NSMutableArray alloc] init];
NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"chi.xml"];
NSData *XMLData = [NSData dataWithContentsOfFile:XMLPath];
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
NSArray *items = [rssParser nodesForXPath:@"/template/item" error:nil];
for (CXMLElement *node in items) {
int counter;
if([[[node attributeForName:@"type"] stringValue] isEqualToString:@"label"]){
for(counter = 0; counter < [node childCount]; counter++) {
[listOfNames addObject:[[node childAtIndex:counter] stringValue]];
}
}
...
并用于此功能:
-(void)setupPage{
[scroll setCanCancelContentTouches:NO];
scroll.indicatorStyle=UIScrollViewIndicatorStyleWhite;
scroll.clipsToBounds=YES;
scroll.scrollEnabled=YES;
scroll.pagingEnabled=NO;
int y=Y;
CGFloat cy=0;
int count=[listOfProperties count];
int total=count;
for(int i=0;i<count;i++){
NSString *class=[[[NSString alloc] initWithFormat:@"%@",[(NSObject *)[listOfProperties objectAtIndex:i] class]] autorelease];
if([class isEqualToString:@"textFieldCell"]){
((textFieldCell*)[listOfProperties objectAtIndex:i]).str=[listOfNames objectAtIndex:i];
[((textFieldCell*)[listOfProperties objectAtIndex:i]) setTarget:scroll];
((textFieldCell*)[listOfProperties objectAtIndex:i]).view.frame=CGRectMake(X,y,self.view.frame.size.width - remProfX,cellProfH);
[((textFieldCell*)[listOfProperties objectAtIndex:i]) setImage:[self getImageName:i maxValue:(count-1)]];
[scroll addSubview:((textFieldCell*)[listOfProperties objectAtIndex:i]).view];
}
else{
if([class isEqualToString:@"comboBoxCell"]){
((comboBoxCell*)[listOfProperties objectAtIndex:i]).str=[listOfNames objectAtIndex:i];
[((comboBoxCell*)[listOfProperties objectAtIndex:i]) setTarget:self.view];
((comboBoxCell*)[listOfProperties objectAtIndex:i]).view.frame=CGRectMake(X,y,self.view.frame.size.width - remProfX,cellProfH);
[((comboBoxCell*)[listOfProperties objectAtIndex:i]) setImage:[self getImageName:i maxValue:(count-1)]];
[scroll addSubview:((comboBoxCell*)[listOfProperties objectAtIndex:i]).view];
}
else{
if([class isEqualToString:@"dateCell"]){
((dateCell*)[listOfProperties objectAtIndex:i]).str=[listOfNames objectAtIndex:i];
[((dateCell*)[listOfProperties objectAtIndex:i]) setTarget:self.view];
((dateCell*)[listOfProperties objectAtIndex:i]).view.frame=CGRectMake(X,y,self.view.frame.size.width - remProfX,cellProfH);
[((dateCell*)[listOfProperties objectAtIndex:i]) setImage:[self getImageName:i maxValue:(count-1)]];
[scroll addSubview:((dateCell*)[listOfProperties objectAtIndex:i]).view];
}
}
...
的dealloc:
- (void)dealloc {
[listOfNames release];
[listOfProperties release];
[listOfGroupNames release];
[listOfCheckBoxNames release];
[listOfCheckBoxes release];
[listOfButtons release];
[scroll release];
[super dealloc];
}
答案 0 :(得分:1)
如果您使用以下方法之一将NSArray创建为自动释放对象,则可能会发生这种情况:
+ array
+ arrayWithArray:
+ arrayWithContentsOfFile:
+ arrayWithContentsOfURL:
+ arrayWithObject:
+ arrayWithObjects:
+ arrayWithObjects:count:
然后在关闭UIViewController的dealloc方法中释放这个数组。
修改强> 顺便说一下,类字是重新设置的,就像你在这里使用它一样糟糕:
NSString *class=[[[NSString alloc] initWithFormat:@"%@",[(NSObject *)[listOfProperties objectAtIndex:i] class]] autorelease];