如果已经有人问过,我很抱歉,但问题来了:

当我快速滚动 tableView 时,我收到此消息:

由于未捕获的异常“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];

我发现这是由于过度保留或释放不足造成的,但我没有找到解决方法。

有什么帮助吗?

有帮助吗?

解决方案

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

在此代码中,UITextview的标记为“5”,我认为您可能会给此视图提供不同的ID。首先。

我有similler问题....我发现我的标签是TextView和图像视图的衍射。

如何更改视图标记?

首先选择视图(即uitextview),而不是转到属性检查器选项卡.....在'查看'下,您将找到“标记”写 5.

我希望它可能对你有所帮助。

其他提示

setText 是一个 UITextView 方法不 UIImageView. 。现在正如评论中提到的, cellText 不是 UITextView 举例来说,似乎是 UIImageView 例如,然后你试图打电话 setText 方法从一个 UIImageView 导致应用程序崩溃的实例。尝试测试它以确保:

   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];

这样,如果 cellText 不是 UITextView 例如,它会为您初始化一个。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top