2012-01-11 6 views
1

私はEXC_BAD_ACCESSを受け取っていますが、その理由を理解できません。 これはコードです:カスタムクラスを含むNSMutableArrayのEXC_BAD_ACCESS

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    TDBadgedCell *cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 


    SubscriptionArray * element =[reader.subscriptions objectAtIndex:[indexPath row]]; 



    [cell.textLabel setText:element.title]; // <--- error at this line of code 



    return cell; 
} 

reader.subscritions 81個の要素(私はのNSLogでverificated確信している)が、私は、私はこのエラーを持っているタイトルを設定取得しようとすると...なぜが含まれているNSMutableArrayのでしょうか? SubscritionArrayは、3つの文字列と1つのintを含むカスタムクラスです。

カスタムクラス: ヘッダー

#import <Foundation/Foundation.h> 

@interface SubscriptionArray : NSObject{ 
    NSString *title; 
    NSString *source; 
    NSString *htmlUrl; 
    NSInteger count; 
} 

@property (nonatomic,retain) NSString *title; 
@property (nonatomic,retain) NSString *source; 
@property (nonatomic,retain) NSString *htmlUrl; 
@property (nonatomic) NSInteger count; 
@end 

実装:

#import "SubscriptionArray.h" 

@implementation SubscriptionArray 
@synthesize title,source,htmlUrl,count; 

-(void)dealloc{ 
    [title release]; 
    [source release]; 
    [htmlUrl release]; 

} 

- (id)initWithCoder:(NSCoder *)decoder { 
    if (self = [super init]) { 

     title = [[decoder decodeObjectForKey:@"title"] retain]; 
     source = [[decoder decodeObjectForKey:@"source"] retain]; 
     htmlUrl = [[decoder decodeObjectForKey:@"htmlUrl"] retain]; 
     //count = [decoder decodeIntForKey:@"count"]; 

    } 
    return self; 
} 

- (void)encodeWithCoder:(NSCoder *)encoder { 

    if (title) [encoder encodeObject:title forKey:@"title"]; 
    if (source) [encoder encodeObject:source forKey:@"source"]; 
    if (htmlUrl) [encoder encodeObject:htmlUrl forKey:@"htmlUrl"]; 
    //if (count) [encoder encodeInteger:count forKey:@"count"]; 
} 



@end 

EDIT 股関節の私が何を得る * - [__ NSArrayM objectAtIndex:]:割り当て解除に送信されたメッセージインスタンス0xe5a8260

そしてそれは、私はNSMutableArrayの

subscriptions = [[NSMutableArray alloc]init]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains 
    (NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 


    //make a file name to write the data to using the 
    //documents directory: 
    NSString *fullFileName = [NSString stringWithFormat:@"%@/subscriptions", documentsDirectory]; 
    [subscriptions removeAllObjects]; 
    subscriptions = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFileName]; 
+0

SubscriptionArrayのヘッダファイルを含めることはできますか?タイトルプロパティが宣言されていると仮定しています。 –

+0

私は... –

+1

EXC_BAD_ACCESSに遭遇すると、まずNSZombieが有効になります。 – tia

答えて

0

私は、サブスクリプション要素のあなたの配列は、あなたの行インデックス(単なる推測)にアップ一致していないことを言ってベンチャー思いを設定する方法を説明します。 'element'を宣言した直後で、ラベルを設定しようとする前に、デバッガのブレークポイントを設定することをお勧めします。

+0

ここに同意します。あなたが取り出した結果は何でもかまいません。タイトルのために空白でも無しでもかまいません。 –

+0

*** - [__ NSArrayM objectAtIndex:]:メッセージが割り当て解除されたインスタンスに送信されました0xe5a8260 –

+0

自動または手動参照カウントを使用していますか?あなたが解放されたオブジェクトにアクセスしようとしているようです(これはmutable配列そのものか内部のオブジェクトかもしれませんが、何かが過解放されています)... – isaac

0

で参照しようとする前に、reader.subscriptionsの可変配列が割り当て解除されていることを確認する必要があります。 subscriptions配列がリーダーによって適切に保持またはコピーされていて、余分なものがreleaseまたはautoreleaseメッセージをどこかに送信することでオーバーリリースしていないことを確認してください。 readerインスタンスのクラスから関連するコードを送信すると役立ちます。