[UIImageView setText:]:Unbekannter Selektor an Instanz gesendet
-
13-12-2019 - |
Frage
Es tut mir leid, wenn die Frage bereits gestellt wurde, aber hier kommt das Problem:
Ich erhalte diese Meldung, wenn ich schnell durch die Tabellenansicht scrolle:
App wird aufgrund der nicht abgefangenen Ausnahme „NSInvalidArgumentException“ beendet, Grund:'-[UIImageView setText:]:Unbekannter Selektor an Instanz 0x8a8f8d0 gesendet
Hier ist mein Code:
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];
...
Und die Zeile, die diese Ausnahme auslöst, ist:
[cellText setText:postText];
Ich habe gesehen, dass es an einer übermäßigen Beibehaltung oder unzureichenden Freigabe liegt, aber ich finde keine Möglichkeit, das Problem zu beheben.
Irgendeine Hilfe, bitte?
Lösung
In dieser Codezeile ist Ihr Tag für UitextView "5", ich glaube, Sie haben für diese Ansicht möglicherweise unterschiedliche ID gegeben.Zuerst.
Ich hatte Similler-Problem .... Ich fand heraus, dass mein Tag für Textview- und Bildansicht unterschiedlich war.
Wie man Tag für eine Ansicht wechselt?
Wählen Sie zuerst die Ansicht (dh uitextview) aus und gehen Sie zur Registerkarte "Inspute Inspector" ... unter "Ansicht" finden Sie "Tag" 5.
Ich hoffe, es kann Ihnen hilfreich sein.
Andere Tipps
setText
ist ein UITextView
Methode nicht UIImageView
.Nun, wie im Kommentar erwähnt, ist der Zelltext kein UITextView
Beispielsweise scheint es so zu sein UIImageView
Beispiel, dann versuchst du anzurufen setText
Methode von a UIImageView
Instanz, die zum Absturz der App führt.Probieren Sie es aus, um sicherzustellen, dass:
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];
Auf diese Weise, wenn cellText
ist nicht UITextView
Beispielsweise wird es eines für Sie initiieren.