2011-09-23 171 views
1

我简单的认为是一个UINavigationController的第三级,这表明从笔尖一个空表,这里是.m文件的代码:的iOS - UITableViewCell的初始化失败,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 

当我运行它,设备死机和调试器说是有这条线一EXC_BAD_ACCESS:

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

我相同的代码在UINavigationController的第二个层次,它做工精细,真的不要”不明白什么是错的。

感谢所有帮助:)

回答

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

static NSString *CellIdentifier = "Cell"; 

更超过

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

当添加@ ......难以置信......叫我白痴:d非常感谢你:) –

+0

我不明白他们为什么不要阅读警告...... – Nekto

+0

@Marco Faion在这个世界上没有人是完美的..practice会让我们变得最好。就是这样。酷。 –

1

可能是你应该return cell在这个方法:

- (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; 
} 

更新时间:

而且如前所述@AppleVijay初始化CellIdentifier

+0

为你的诚实+1 –