【发布时间】:2014-04-12 13:19:47
【问题描述】:
我的项目在表格视图中显示结果时遇到问题。我在 NSmutableArray "ActosPueblo" 中有事件 alloc 并且 uitableview 正确打印了这个结果,但是当点击行时出现错误 "NSArrayM objectatindex index 1 beyond bounds [0..0]" 或者只显示来自不同行的详细信息而不是点击行。
我在 .m 中的代码是...
- (void)viewDidLoad{
[super viewDidLoad];
NSString *titulo = [NSString stringWithFormat:@"%@ %@, %@", tipoNombreDia, tipoNumeroDia, tempNombreMes];
self.title = titulo;
//loading antes de pedir los datos
[SVProgressHUD showWithStatus:@"Cargando..." maskType:SVProgressHUDMaskTypeBlack];
[self cargarActosPueblos];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [actosPueblo count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSDictionary *dictionary =[actosPueblo objectAtIndex:section];
NSArray *array = [dictionary objectForKey:@"ActosPueblo"];
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CalendarioActosViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *dic = [actosPueblo objectAtIndex:indexPath.section];
NSArray *array = [dic objectForKey:@"ActosPueblo"];
NSString *tipoEvento = [[array objectAtIndex:indexPath.row] objectForKey:@"TipoEventos"];
cell.labelEvento.text = tipoEvento;
NSString *tipoMunicipio = [[array objectAtIndex:indexPath.row] objectForKey:@"Municipio"];
cell.labelMunicipio.text = tipoMunicipio;
NSString *tipoGanaderia = [[array objectAtIndex:indexPath.row] objectForKey:@"Ganaderias"];
cell.labelGanaderia.text = tipoGanaderia;
NSString *tipoFecha = [[array objectAtIndex:indexPath.row] objectForKey:@"Fecha"];
cell.labelFecha.text = tipoFecha;
NSString *tipoHora = [[array objectAtIndex:indexPath.row] objectForKey:@"Hora"];
cell.labelHora.text = tipoHora;
NSString *indexP = [NSString stringWithFormat:@"fila: %ld", (long)indexPath.row];
cell.index.text = indexP;
NSString *urlImagen = [[array objectAtIndex:indexPath.row] objectForKey:@"ImagenEvento"];
//precarga imagen con SDWebImage
//precarga imagen con SDWebImage
if([urlImagen length] == 0){
cell.celdaThumb.image = [UIImage imageNamed:@"sin-icono.png"];
}else{
[cell.celdaThumb setImageWithURL:[NSURL URLWithString:urlImagen] placeholderImage:[UIImage imageNamed:@"sin-icono.png"]];
}
actos = [[NSMutableArray alloc] init];
for (NSDictionary* dic in array) {
CalendarioActos *actPob = [[CalendarioActos alloc] init];
actPob.apGanaderia= [dic objectForKey:@"Ganaderias"];
actPob.apEvento = [dic objectForKey:@"TipoEventos"];
actPob.apFecha = [dic objectForKey:@"Fecha"];
actPob.apHora = [dic objectForKey:@"Hora"];
actPob.apMunicipio = [dic objectForKey:@"Municipio"];
actPob.apProvincia = [dic objectForKey:@"Provincia"];
actPob.apToroImagen = [dic objectForKey:@"Imagen"];
[actos addObject:actPob];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([self.checkedIndexPath isEqual:indexPath]){
self.checkedIndexPath = nil;
}else{
self.checkedIndexPath = indexPath;
}
CalendarioActosViewCell *cell =(CalendarioActosViewCell*) [tableView cellForRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:@"actoTodiaActo" sender:cell];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"actoTodiaActo"]){
CalendarioActosDetallesViewController *detallesController= (CalendarioActosDetallesViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [self.tableViewAP indexPathForSelectedRow];
cal = [actos objectAtIndex:indexPath.row];
/* NSString *index = [NSString stringWithFormat:@"%lu", [actos count]];
//alerta campo vacío
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Count Actos" message:index delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
// Mostrar alerta
[alert show];*/
detallesController.tempEvento = cal.apEvento;
detallesController.tempFecha = cal.apFecha;
detallesController.tempGanaderia = cal.apGanaderia;
detallesController.tempHora = cal.apHora;
detallesController.tempImagen = cal.apToroImagen;
detallesController.tempMunicipio = cal.apMunicipio;
detallesController.tempProvincia = cal.apProvincia;
NSString *datos = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ %@", cal.apEvento, cal.apFecha, cal.apGanaderia, cal.apHora, cal.apMunicipio, cal.apProvincia, cal.apToroImagen];
NSLog(@"pasamos: %@", datos);
}
}
“ActosPueblo”包含来自 url 的数据以及来自 viewload 中函数“cargarActosPueblos”的 JSON。
我从 stackoverflow.com 看到其他问题,但没有结果。
请检查我的代码并接受任何建议。
感谢和问候
【问题讨论】:
标签: ios objective-c uitableview