gpt4 book ai didi

iOS - UITableViewCell 初始化失败,EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-12-01 18:02:17 26 4
gpt4 key购买 nike

我有一个简单的 View ,它是 UINavigationController 的第三级,它显示了一个 nib 的空表,这是 .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 的第二级有相同的代码,它工作正常,真的不明白出了什么问题。

谢谢你的帮助 :)

最佳答案

  static NSString *CellIdentifier =@"Cell";

不是
  static NSString *CellIdentifier = "Cell";

而且
 return cell;//not found on ur code

关于iOS - UITableViewCell 初始化失败,EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7527278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com