[UIImageView SetText :] : 인스턴스로 전송 된 인식 할 수없는 선택기
-
13-12-2019 - |
문제
이미 묻는 경우 죄송합니다. 그러나 여기에 문제가 있습니다 :
테이블보기를 빨리 스크롤 할 때이 메시지를 얻습니다.
앱을 종료하지 않는 예외의 예외 'nsinvalidargumentException', 이유 : '- [UIImageView SetText :] : 인식 할 수없는 선택기가 인스턴스 0x8A8F8D0'
로 전송됩니다.여기에 내 코드가 있습니다 :
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];
...
.
과이 예외를 발사하는 선은 다음과 같습니다.
[cellText setText:postText];
.
나는 그것이 지나치게 유지되거나 밑줄로 인한 것이라는 것을 알았지 만, 나는 그것을 고치는 방법을 찾지 못한다.
도움말 plz?
해결책
UITextView *cellText = (UITextView *)[cell viewWithTag:5];
.
이 코드 라인에서 UITextView의 태그는 "5"이며,이 뷰에 대한 다른 ID를 주어 낼 수 있다고 생각합니다.첫 번째.
나는 similler 문제가 있었다 .... 나는 내 태그가 textview 및 이미지보기에 대해 다른 것을 발견했다는 것을 발견했다.
태그를보기 위해 변경하는 방법
먼저보기 (예 : UITEXTVIEW)를 선택하고 속성 관리자 탭 ..... '에서'태그 '를 참조하십시오. 5.
나는 그것이 당신에게 도움이 될 수 있기를 바랍니다.
다른 팁
setText
는 UITextView
가 아닌 UIImageView
메소드입니다.이제 댓글에서 언급했듯이 CellText는 UITextView
인스턴스가 아니므로 앱이 충돌하는 UIImageView
인스턴스에서 setText
메서드를 호출하려고 시도하는 것으로 보입니다.그것을 테스트하기 위해 테스트를 시도하십시오.
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];
.
UIImageView
가 cellText
인스턴스가 아니면 하나는 사용자를위한 init입니다.