Array count throwing exception
* -[__NSArrayM count]: message sent to deallocated instance 0x5edd5e0
I am Getting this type of exception and its crashing my app. The code is:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section == 0){
return ([billDetials count]+ 1);
}
int rows = ([billers count] + 1);
return rows;
}
[billers count] for this statement i am getting that exception... Here billers is NSMutableArray having开发者_如何学运维 6 objects. tableView consists of 2 sections.
so I should get the array count as 6 but its not happenning....
It sounds like the billers array isn't getting retained properly. Make sure it's either a retained property, or that you're retaining it properly when you create that array.
Read and fully understand this: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html%23//apple_ref/doc/uid/10000011i
It appears that the 'billers' NSArray is being deallocated before you call the count method on it. This could be due to autorelease or a manual release before you send the count method.
If you are initializing billers using "alloc" and "init" then you are likely releasing the object too soon. If you are initializing it using a convenience method or with "autorelease", then the object is being garbage collected too soon (you need to retain it).
精彩评论