iOS - UITableViewCell 初始化失败,EXC_BAD_ACCESS
我有一个简单的视图,它是 UINavigationController 的第三级,它显示笔尖中的一个空表,这是 .m 文件的代码:
#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 的第二级有相同的代码,它工作正常,真的不明白出了什么问题。
感谢您的帮助:)
i've a simple View that is the third level of a UINavigationController, it show an empty table from a nib, here is the code of the .m file:
#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
When i run it, the device crash and the debugger say that there is a EXC_BAD_ACCESS at this line:
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
i've the same code in the second level of the UINavigationController and it work fine, realy don't understand what's wrong.
Thanks for any help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不再
结束
not
more over
也许您应该在此方法中
返回单元格
:更新:
正如@AppleVijay提到的,在初始化
CellIdentifier
时添加@
May be you should
return cell
in this method:Updated:
And as mentioned @AppleVijay add
@
when initializingCellIdentifier