开发者

iphone app crashing when I'm using an NSMutableDictionary

Got this code in my controllers (void)viewDidLoad method

self.purchasesPerClassification = [NSMutableDictionary 
                                  dictionaryWithObjects:[NSArray arrayWithObjects:@"Moo",nil] 
                                  forKeys:[NSArray arrayWithObjects:@"MooKey",nil]
                                  ];

as far I can under stand these are auto release as I have not used alloc init, and开发者_运维问答 in my dealloc i have

[self.purchasesPerClassification release];

this is part of a controller with UITableViewController and this controller is created an loaded from a main container and added to the main contollers navigationController this seems to make my app crash in the simulator as when I dont have it in the code it works fine any pointers on why this is crashing

heres the .h

@interface FirstAiderInsurancePurchasesViewController : UITableViewController {

    NSArray * availableClassifications;

    NSMutableDictionary * purchasesPerClassification;

}

@property(nonatomic, retain) NSArray * availableClassifications;
@property(nonatomic, retain) NSMutableDictionary * purchasesPerClassification;

@end

and heres the .m parts

@implementation FirstAiderInsurancePurchasesViewController
@synthesize availableClassifications;
@synthesize purchasesPerClassification;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.availableClassifications = [NSMutableArray arrayWithObjects:@"Completed",@"Recover's",nil];

    self.purchasesPerClassification = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Object",nil]
                                                                          forKeys:[NSArray arrayWithObjects:@"ObjectKey",nil]];

}
- (void)dealloc {
    [super dealloc];
    self.availableClassifications = nil;
    self.purchasesPerClassification = nil;
}

I've tried both

[purchasesPerClassification release];

as well and its crashing when I go back to the root controller


Firstly, what is the property definition of purchasesPerClassification?

Anyway, assuming it's copy or retain, you probably want either:

self.purchasesPerClassification = nil;

or

[purchasesPerClassification release];


[NSMutableDictionary dictionaryWithObjects] return an autoreleased instance you have not to [self.purchasesPerClassification release];

but [purchasesPerClassification release]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜