iOS UITableView gets EXC_BAD_ACCESS when user interracts
I'm starting my first iOS app and I encounter an error that occurs only when user touches the UItableView. THis app is an helper to conjugate verbs in japanese. Here is how it works:
I have a first view that asks user a japanese verb in alphabet. I create an instance of a Conjuger class that copies the verb entered and prepares the analysis. I create an instance of my resultViewController. I associate my conjug object to a property of that controller. I modally display the view. The resultViewController displays everything fine, all datas being loaded from the Conjuger object created from its parent view.
But, if I touch the screen to scroll the view, it gets me an error EXC_BAD_ACCESS. I tried to debug it, but I'm not good enough yet to find where the problem lies. I suspect my conjug object to be released. The odd is tat the attribute of that object "verb" is still intact, but other properties are empty... How come?
Here my Conjuger object declaration:
@interface Conjuger : NSObject
{
NSString *verb;
//parties qui concernent l'analyse du verbe
//=========================================
int group;
NSString *verbEnd; //la terminaison du verbe
NSString *verbBase; //la base du verbe que l'on emploi dansl es conjugaisons
//declinaisons possibles
//======================
/*
Les clefs sont :
pre : present ou pas : passé
a : affirmatif ou n : négatif
n : neutre ou p : poli
*/
NSMutableDictionary *declinaisons;
//les declinaisons vont etre separees en section pour la table view
int declinaisonsSections;
//Titres des sections
NSArray *sectionsTitles;
}
@property (nonatomic, retain) NSString *verb;
@property (nonatomic) int group;
//@property (nonatomic, retain) NSMutableDictionary *declinaisons;
-(Conjuger *) initWithVerb:(NSString *) verb_;
//analyse du verb (recherche du groupe etc...)
-(int) _analyse;
//action de conjugaison du verbe
-(BOOL) conjugate;
//nombre de sections disponibles
-(NSInteger) sectionsCount;
//nombre de lignes dans une section donnee
-(NSInteger) sectionLinesCount:(NSInteger) sectionId;
//permet deretourner le titre d'une section
-(NSString *) sectionTitle:(NSInteger) sec;
//permet de retourner une declinaison pour une section precise
-(NSString *) declinaisonsBySection:(int) sec sectionLine:(int) secline;
@end
My UITableView doesn't have any delegate, but only my ResultViewController as a DataSource. The EXC_BAD_ACCESS error appears in the method titleForHeaderInSection. This method contains :
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [conjug sectionTitle:section];
}
THe methos is called after loading, by the UITableView I suspect, but as this controller is not a UITableViewDelegate, why is this method called on user action? Just a scroll by the way...
My UITableView doesn't take all the screen and is placed into a view.
I don't know what details I can add, please ask if you need any informations. I can post more code or screenshots if needed.
Edit : Here is the code where I instanciate my Conjuger object and assign it to my sescond view controller
//creation de l'objet conjuger qui servira a afficher les resultats dans la vue modale
Conjuger *conjug = [[[Conjuger alloc] initWithVerb:verb.text] autorelease];
//chargement de la vue modale
ConjugerResultsViewController *res = [[[ConjugerResultsViewController alloc] init] autorelease];
res.conjug = conjug;
//affichage
[self presentModalViewController:res animated:YES];
I have an autorelease here, but I don't feel my object to be release, or not completly if it's possible. My conjuger attribute "verb" still contains the data, but not my sectionsTitles... Should I declare all my properties with @property (nonatomic, retain) ? I thought @property to be used only if our attributes have to be called from outside of our object, am I wrong? I feel confused now :(
But I changed my attributes with @property and I access them by "self" as proposed and IT WORKS! But still I don't understand why... I'm trying to find some more objective-c readings, my C courses are f开发者_运维知识库ar behind me now -_-.
I'll investigate with Apple-i in Xcode4 as proposed, it can be usefull for further problems.
Thank you for your reading and your help.
If the crash is in [conjug sectionTitle:], I'd guess that your section titles are a zombie. Make sure you retain the section titles array.
精彩评论