Pregunta

Perdón si ya se ha preguntado, pero aquí viene el problema:

Recibo este mensaje cuando me desplazo rápidamente por tableView:

Finalizando la aplicación debido a una excepción no detectada 'NSInvalidArgumentException', motivo:'-[UIImageView setText:]:selector no reconocido enviado a la instancia 0x8a8f8d0'

Aquí está mi código:

   NewsVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:AudioCellIdentifier];

   if (cell == nil) {
       cell = [[NewsVideoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AudioCellIdentifier];
   }


   cell.backgroundView = [ [UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"news_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 10, 0)] ];  
   cell.selectedBackgroundView = [ [UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"news_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 10, 0)] ];



   UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
   [cellLabel setText:[masjid objectForKey:@"name"]];

   UILabel *cellDate = (UILabel *)[cell viewWithTag:2];
   [cellDate setText:[[news objectAtIndex:indexPath.row] objectForKey:@"date"]];       

   UIImageView *cellImage = (UIImageView *)[cell viewWithTag:3];
   NSString *imagePath = [masjid objectForKey:@"thumb"];
   [cellImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@", imagePath]]];

   UITextView *cellText = (UITextView *)[cell viewWithTag:5];
   NSString *postText = [[news objectAtIndex:indexPath.row] objectForKey:@"title"];

   [cellText setText:postText];

   ...

Y la línea que dispara esta excepción es:

   [cellText setText:postText];

Vi que se debe a una retención excesiva o una liberación insuficiente, pero no encuentro la manera de solucionarlo.

¿Alguna ayuda por favor?

¿Fue útil?

Solución

UITextView *cellText = (UITextView *)[cell viewWithTag:5];

En esta línea de código, su etiqueta para uitextview es "5", creo que es posible que haya dado una identificación diferente para esta vista.Primero.

Tuve un problema simillero ... Descubrí que mi etiqueta estaba diferente para la vista de texto y la vista de la imagen.

¿Cómo cambiar la etiqueta para una vista?

Primero, seleccione la vista (es decir, UiteXTView) y para ir a la pestaña Inspector de atributos ..... bajo la 'Ver' encontrará 'Etiqueta' escribir allí 5.

Espero que pueda ser útil para usted.

Otros consejos

setText es un UITextView método no UIImageView.Ahora, como se menciona en el comentario, cellText no es un UITextView Por ejemplo, parece ser UIImageView ejemplo, entonces estás intentando llamar setText método de un UIImageView instancia que hace que la aplicación falle.Intente probarlo para asegurarse:

   UITextView *cellText = (UITextView *)[cell viewWithTag:5];
   if([cellText class] != [UITextView class]){
        cellText = [[UITextView alloc]init];
   }
   NSString *postText = [[news objectAtIndex:indexPath.row] objectForKey:@"title"];

   [cellText setText:postText];

De esta manera, si cellText no es UITextView Por ejemplo, iniciará uno por usted.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top