새 섹션에서 뉴스가 흐려지는 앱을 제작하고 있습니다. 섹션을 선택하려면 UIPickerView를 사용하고 선택한 섹션의 뉴스를 UITableView에 표시하십시오. 백엔드 2 NSMutable 배열을 사용합니다. 그 중 하나는 모든 뉴스를 저장하는 것이며, 다른 하나는 섹션 선택을 위해 필터링 된 뉴스를 저장하는 것입니다. 모든 것이 정상이지만 섹션을 선택하면 메서드가 뉴스를 필터링하고 배열에서로드하지만 tableview가 데이터를 다시로드하지 않았고 tableview를 다시로드하면 앱이 다운됩니다. 누구든지 새 분리를 선택할 때 테이블 뷰의 모든 셀을 다시로드 할 사람을 알고 있습니다.UITickerView의 선택기에 따라 UITableView 데이터를 업데이트합니다.
이것은 내 코드의 일부입니다.
- (void)viewDidLoad {
[super viewDidLoad];
arraySecciones = @[@"Todas",@"Agua Potable",@"Agua Residual",@"Centro I+D+I",@"Cooperacion",@"Residuos"];
seccionesPicker = [[UIPickerView alloc] init];
NSDate *fecha = [[NSDate alloc] initWithTimeIntervalSince1970:1431231];
arrayNoticias = [[NSMutableArray alloc]init];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 1" body:@"Cuerpo 1" section:@"Agua Potable" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 2" body:@"Cuerpo 2" section:@"Residuos" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 3" body:@"Cuerpo 3" section:@"Cooperacion" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 4" body:@"Cuerpo 4" section:@"Cooperacion" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 5" body:@"Cuerpo 5" section:@"Cooperacion" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 6" body:@"Cuerpo 6" section:@"Agua Potable" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 7" body:@"Cuerpo 7" section:@"Agua Residuale" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 8" body:@"Cuerpo 8" section:@"Agua Potable" date:fecha]];
[arrayNoticias addObject:[[Noticia alloc] initWithTitle:@"Noticia 9" body:@"Cuerpo 9" section:@"Centro I+D+I" date:fecha]];
seccionSelecccionada = @"Todas";
arrayNoticiasFiltrado = [[NSMutableArray alloc]init];
[self getNoticiasArrayForSeccion];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"Fila Seleccionada %ld",(long)row);
switch (row) {
case 0:
self.seccionSelecccionada = @"Todas";
break;
case 1:
self.seccionSelecccionada = @"Agua Potable";
break;
case 2:
self.seccionSelecccionada = @"Agua Residual";
break;
case 3:
self.seccionSelecccionada = @"Centro I+D+I";
break;
case 4:
self.seccionSelecccionada = @"Cooperacion";
break;
case 5:
self.seccionSelecccionada = @"Residuos";
break;
}
seccionLabel.text = seccionSelecccionada;
[self getNoticiasArrayForSeccion];
}
-(void)getNoticiasArrayForSeccion
{
[self.arrayNoticiasFiltrado removeAllObjects];
for(int x=0; x<arrayNoticias.count; x++)
{
Noticia *noticiaAux = [arrayNoticias objectAtIndex:x];
if ([self.seccionSelecccionada isEqualToString:@"Todas"])
[arrayNoticiasFiltrado addObject:noticiaAux];
else if([noticiaAux.seccion isEqualToString:self.seccionSelecccionada])
[arrayNoticiasFiltrado addObject:noticiaAux];
}
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Noticia *noticiaAux = [[Noticia alloc] init];
noticiaAux = [arrayNoticiasFiltrado objectAtIndex:indexPath.row ];
NoticiasTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"celdaNoticias"];
if(!cell)
cell =[[NoticiasTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"celdaNoticias"];
cell.titular.text = noticiaAux.titular;
cell.seccion.text = noticiaAux.seccion;
NSLog(@"Pintando : %@",cell.titular.text);
return cell;
}
http://i.stack.imgur.com/vS8c8.png http://i.stack.imgur.com/a8pIl.png 모든 문제의
하는 배열에서 사용자가 데이터를 가져 오는하고있는 tableview로 표시 :
그냥 기능이 같은
-(void)getNoticiasArrayForSeccion
의 끝에[noticiasTable reloadData]
전화? –
어레이에서 데이터를 다시로드하도록 테이블에 알리기 위해 tableview의'reloadData' 메소드를 호출해야합니다. –
오류를 게시하십시오. 그 질문에 매우 중요합니다 –