[英]iOS: Custom Cell lldb Memory access error
Still having trouble accessing variables to load into a custom cell. 仍然无法访问变量以加载到自定义单元格中。 I have a xib, .h, .m named InSeasonCell. 我有一个名为InSeasonCell的xib,.h,.m。 I have a IBOutlet InSeasonCell *_cell; 我有一个IBOutlet InSeasonCell * _cell; in .h of rootviewcontroller. 在rootviewcontroller的.h中。 I get lldb error for accessing my productAtIndex values. 访问我的productAtIndex值时出现lldb错误。 Any help would be great. 任何帮助都会很棒。 I was told to read the Table View Programming Guide. 有人告诉我阅读《 Table View编程指南》。
I create 我创造
_dataController = [[InSeasonProductDataController alloc] init];
Which is init in the rootviewcontroller but passed to an other object which populates it with Product objects. 它是rootviewcontroller中的init,但是传递给另一个用Product对象填充它的对象。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"InSeasonCell";
InSeasonCell *cell = (InSeasonCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = _cell;
_cell = nil;
}
if(_dataController!=nil){
Product *productAtIndex = [_dataController objectInListAtIndex:indexPath.row];
// Configure the cell...
cell.name.text = productAtIndex.name;
cell.week.text = productAtIndex.week;
cell.image.image = productAtIndex.image;
}
return cell;
}
I looked through my code and found that I am passing an object created in one class to the other. 我查看了一下代码,发现正在将在一个类中创建的对象传递给另一个。 for example: 例如:
-(id)initWithDataController:(InSeasonProductDataController *)dataController spinner: (UIActivityIndicatorView *)spinner{
if(self = [super init]){
_dataController = [dataController retain];
_spinner = [spinner retain];
}
return self;
}
_dataController gets populated with Product objects later in this method and is released. _dataController稍后在此方法中填充Product对象,然后将其释放。
To solve this error you need in your xib file click on cell prototype and in Attribute inspection > Identifier insert the same name as you have in .m file (I write down "cell"): 要解决此错误,您需要在xib文件中单击单元格原型,然后在“属性检查”>“标识符”中插入与.m文件中相同的名称(我记下“ cell”):
in method: 在方法中:
I figured it out. 我想到了。 My Product object initialized variables which I had to do a copy for each variable passed in. This got rid of the lldb error. 我的Product对象初始化了变量,我必须为传入的每个变量做一个副本。这消除了lldb错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.