私は何時間もプログラムをデバッグしていて、実行するたびにエラーEXC_BAD_ACCESS
を受け取っています。
このtutorialの手順に従いましたが、結果はありません。
NSMutableArray "EXC_BAD_ACCESS"
私はいくつかのコードと私の所見を投稿し、誰かが私の問題を解決するのを助けることを望みます。
-(void)grabData{
listOfItems=[[NSMutableArray alloc] init];
NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"list.xml"];
NSData *XMLData = [NSData dataWithContentsOfFile:XMLPath];
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
NSArray *buttons=[rssParser nodesForXPath:@"//item" error:nil];
for (CXMLElement *node in buttons) {
int counter;
if([[[node attributeForName:@"type"] stringValue] isEqualToString:@"photobutton"]){
itListCell *itl=[[itListCell alloc] initWithNibName:@"itListCell" bundle:nil];
itl.rows=0;
itl.iw=0.0;
itl.ih=0.0;
[email protected]"";
[email protected]"";
[email protected]"";
[email protected]"";
[email protected]"";
for(counter = 0; counter < [node childCount]; counter++) {
if([[[node childAtIndex:counter] name] isEqualToString:@"text"]){
NSString * value = [[[node childAtIndex:counter] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([value length] != 0){
itl.text=[[node childAtIndex:counter] stringValue];
}
}
else{
if([[[node childAtIndex:counter] name] isEqualToString:@"uiid"]){
itl.uiid=[[node childAtIndex:counter] stringValue];
}
else{
if([[[node childAtIndex:counter] name] isEqualToString:@"rows"]){
itl.rows=[[[node childAtIndex:counter] stringValue] intValue];
}
else{
if([[[node childAtIndex:counter] name] isEqualToString:@"icon"]){
itl.iUrl=[[node childAtIndex:counter] stringValue];
CXMLElement *n=(CXMLElement*)[node childAtIndex:counter];
NSString *resString=[[n attributeForName:@"resize"] stringValue];
NSArray *resArray= [resString componentsSeparatedByString: @","];
itl.iw=[[resArray objectAtIndex:0] floatValue];
itl.ih=[[resArray objectAtIndex:1] floatValue];
}
else{
if([[[node childAtIndex:counter] name] isEqualToString:@"action"]){
itl.action=[[((CXMLElement*)[node childAtIndex:counter]) attributeForName:@"name"] stringValue];
NSArray *getaUrl=[node elementsForName:@"action"];
for(CXMLElement *n in getaUrl){
for(int c = 0; c < [n childCount]; c++) {
if([[[n childAtIndex:c] name] isEqualToString:@"url"]){
itl.aUrl=[[n childAtIndex:c] stringValue];
}
}
}
}
}
}
}
}
}
[listOfItems addObject:itl];
[itl release];
}
}
}
- (void)dealloc {
[listOfItems release];
[scroll release];
[super dealloc];
}
NSMutableArray *listOfItems
がこの問題を引き起こしているようです。
grabData
関数で割り当てにretainを追加してもエラーは発生しません。
dealloc
機能から[listOfItems release];
を削除するとエラーは発生しなくなります。
しかし、私がgrabData
関数の最後の行を削除すると、それ以上のエラーは発生しなくなります。
私は立ち往生しており解決策を見つけることができません。誰かがこの問題を解決する手助けをすることができれば非常に感謝しています。
EDIT: 要求されるように、これはitListCell
//
// itListCell.h
// TemplatesTest
//
// Created by foobyte on 6/30/11.
// Copyright 2011 FOO. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Constants.h"
#import "imageDelegate.h"
@interface itListCell : UIViewController {
UIImageView *i;
UILabel *l;
BOOL imageDidLoad;
CGFloat width;
CGFloat maxCalculatedHeight;
CGSize strSize;
//properties
int rows;
CGFloat iw;
CGFloat ih;
NSString *uiid;
NSString *text;
NSString *action;
NSString *aUrl;
NSString *iUrl;
}
@property (nonatomic, retain) UIImageView *i;
@property (nonatomic, retain) UILabel *l;
@property (nonatomic, retain) NSString *uiid;
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSString *action;
@property (nonatomic, retain) NSString *aUrl;
@property (nonatomic, retain) NSString *iUrl;
@property (nonatomic) int rows;
@property (nonatomic) CGFloat iw;
@property (nonatomic) CGFloat ih;
-(void)setwidth:(CGFloat)w;
-(CGFloat)getMaxHeight;
-(UIImage *)downloadIcon:(NSString *)s;
@end
、ここでの.hのがlistOfItems
内のオブジェクトを使用する関数である:
-(void) setupPage{
[scroll setCanCancelContentTouches:NO];
scroll.indicatorStyle=UIScrollViewIndicatorStyleWhite;
scroll.clipsToBounds=YES;
scroll.scrollEnabled=YES;
scroll.pagingEnabled=NO;
[scroll setBackgroundColor:[UIColor blackColor]];
CGFloat y=0.0;
CGFloat cy=0.0;
int count=[listOfItems count];
for(int i=0;i<count;i++){
[((itListCell *)[listOfItems objectAtIndex:i]) setwidth:self.view.frame.size.width];
CGFloat h=[((itListCell *)[listOfItems objectAtIndex:i]) getMaxHeight];
((itListCell *)[listOfItems objectAtIndex:i]).view.frame=CGRectMake(lITX, y, self.view.frame.size.width-lITM, h);
[scroll addSubview:((itListCell *)[listOfItems objectAtIndex:i]).view];
y+=h;
if(i >= 2)
cy+=h;
}
[scroll setContentSize:CGSizeMake(scroll.frame.size.width, cy+[scroll bounds].size.height)];
}
あなたの 'itl'オブジェクトの1つ(またはそのインスタンス変数/宣言されたプロパティの1つ)がオーバーリリースされているようです。 –
Xcode 4を使用している場合、command-shift-Bはあなたの友人です。 ;) –
あなたは 'itListCell'の.hファイルを投稿できますか?あなたはuuid、text、action、aUrl、およびiURLの各プロパティに対して' copy'または 'retain'を設定する必要があります。 – deanWombourne