У меня есть объект "Consumo"NSMutableArray и UITableView (EXC_BAD_ACCESS)
-(id)initWithDictionary:(NSDictionary *)consumo{
self = [super init];
if (self != nil)
{
fechaLectura = [consumo objectForKey:@"fechaLectura"];
tarifa = [consumo objectForKey:@"tarifa"];
consumoBase = [consumo objectForKey:@"consumoBase"];
consumoHP = [consumo objectForKey:@"consumoHP"];
reactivoLeido = [consumo objectForKey:@"reactivoLeido"];
reactivoFacturado = [consumo objectForKey:@"reactivoFacturado"];
demandaFPLeida = [consumo objectForKey:@"demandaFPLeida"];
demandaFPFacturada = [consumo objectForKey:@"demandaFPFacturada"];
demandaHPLeida = [consumo objectForKey:@"demandaHPLeida"];
demandaHPFacturada = [consumo objectForKey:@"demandaHPFacturada"];
calificacion = [consumo objectForKey:@"consumo"];
}
return self;
}
viewController.h
@interface ConsumoViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UILabel * sumLabel;
NSMutableArray * consumos;
IBOutlet UITableView *tablaConsumo;
NSMutableArray * titulosConsumo;
Consumo * cons;
}
@property (nonatomic,retain) IBOutlet UILabel * sumLabel;
@property (nonatomic,retain) NSMutableArray * consumos;
@property (nonatomic,retain) UITableView * tablaConsumo;
@property (nonatomic,retain) NSMutableArray * titulosConsumo;
@property (nonatomic,retain) Consumo * cons;
@end
viewcontroller.m (включая TableView)
- (void)viewDidLoad
{
consumos = [[NSMutableArray alloc] init];
NSDictionary * dict;
for (int i = 0; i < [suministro count]; i++){ /* suministro = array to dictionary */
dict=[suministro objectAtIndex:i];
cons = [[Consumo alloc] initWithDictionary:dict];
[consumos insertObject:cons atIndex:i];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
detFechaLectura = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 20.0, 120.0, 20.0)] autorelease];
detFechaLectura.tag = LABELSUP1;
[cell.contentView addSubview:detFechaLectura];
}else{
detFechaLectura = (UILabel *)[cell.contentView viewWithTag:LABELSUP1];
}
detFechaLectura.text = [[consumos objectAtIndex:indexPath.row] fechaLectura];
return cell
}
}
Задача:
detFechaLectura.text = [[потребительский объектAtIndex: indexPath.row] fechaLectura]; (Тема 1: Программный сигнал: «EXC_BAD_ACCESS»)
Надеюсь, я могу помочь. спасибо
большой, спасибо. Я думал об этом: @property (неатомный, сохраняющий) NSString * fechaLectura; Retain собирается подсчитать, сколько раз инициализируется. – JohnPortella
См. Мое редактирование :) Если вы используете 'self.fechaLectura', вы используете свойство (и, следовательно, сохраняете). Если вы просто используете 'fechaLectura', тогда вы должны сохранить себя. – deanWombourne