我想使用自定義UITableViewCell構建聯繫人表,但每次嘗試加載視圖時,都會收到EXC_BAD_ACCESS錯誤。UITableView在使用自定義UITableViewCell時拋出EXC_BAD_ACCESS
我的表的代碼如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
if(indexPath.section == 0){
NSString *ilabel = [[[contactDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectAtIndex:0];
NSString *itext = [[[contactDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectAtIndex:1];
CustomCell *cell= [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// Default to no selected style and not selected
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setCellData:ilabel textVal:itext];
return cell;
[ilabel release];
[itext release];
}
}
與我的手機類:
@implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code.
}
return self;
}
- (void)setCellData:(NSString *)ilabel textVal:(NSString *)itext {
_label.text = ilabel;
_text.text = itext;
// Alloc and set the frame
_label.frame = CGRectMake(0, 0, 286, 68);
// Add subview
[self.contentView addSubview:_label];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)dealloc {
[super dealloc];
}
@end
,因爲我完全難倒任何幫助將不勝感激。
你確定'NSString * itext = [[[contactDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectAtIndex:1]; '一直工作?順便說一句,爲你的可執行文件啓用'NSZombieEnabled'並再次查看控制檯,這應該會給出一個更好的提示,指出哪裏出了問題。 – 2011-04-26 07:42:46
可能是因爲contactDetails爲零? – 2011-04-26 07:43:15
不要忘記接受答案... – 2011-04-26 08:33:47