2011-09-23 2 views
1

i AVONS simple vue qui est le troisième niveau d'un UINavigationController, il montre une table vide à partir d'une plume, voici le code du fichier .m:iOS - initialisation UITableViewCell échouez, EXC_BAD_ACCESS

#import "ThirdLevel.h" 


@implementation ThirdLevel 

@synthesize lista, categoria; 


- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSLog(@"Categoria: %@", categoria); 

} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Overriden to allow any orientation. 
    return NO; 
} 


- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc. that aren't in use. 
} 


- (void)viewDidUnload { 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 20; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 100; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    //newtableView.separatorColor = [UIColor clearColor]; 
    static NSString *CellIdentifier = "Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

} 

- (void)buttonPressed:(id)sender { 
    NSLog(@"premuto"); 

} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 

Quand je le lance, le crash de l'appareil et le débogueur dire qu'il ya un EXC_BAD_ACCESS à cette ligne:

 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

j'ai le même code dans le deuxième niveau du UINavigationController et il travaille bien, don realy » Je ne comprends pas ce qui ne va pas.

Merci pour toute aide :)

Répondre

4
static NSString *CellIdentifier [email protected]"Cell"; 

pas

static NSString *CellIdentifier = "Cell"; 

plus sur

return cell;//not found on ur code 
+0

... incroyable ... appelez-moi idiote: D merci beaucoup :) –

+0

Je ne comprends pas pourquoi ils ne pas lire les avertissements .... – Nekto

+0

@Marco Faion personne n'est parfait dans ce monde.la pratique nous rendra mieux.que c'est.cool. –

1

Peut-être vous devriez return cell dans cette méthode:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    //newtableView.separatorColor = [UIColor clearColor]; 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    return cell; 
} 

Mise à jour:

Et comme mentionné @AppleVijay ajouter @ lors de l'initialisation CellIdentifier

+0

+1 pour vous honnête –