2012-07-28 95 views
0

对不起,如果它已经被问过,但来这里的问题:[的UIImageView的setText:]:无法识别的选择发送到实例

我得到这个消息时,我滚动快的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]; 

我看到这是由于过度保留或正在释放,但我没有找到一个方法来解决它。

任何帮助PLZ?

+3

它看起来像标记视图#5是图像视图,而不是文本视图。这可能吗? – dasblinkenlight 2012-07-28 03:37:03

+0

当您将视图分配给标签或textview时,请尝试使用cell.contentView代替单元格 – 2012-07-28 05:21:09

+0

@dasblinkenlight否,带标签的视图#5是文本视图而不是图像视图。这就是为什么我不明白为什么它告诉我[UIImageView setText:]:无法识别的选择器 – Abdessamad 2012-07-28 11:30:54

回答

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

在这行代码中你的TAG for UITextView是“5”,我想你可能已经给出了这个视图的不同ID。首先。

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

如何更改视图的TAG?

首先选择视图(即UITextView的),比去属性检查器选项卡.....在“查看”,你会发现“标签”写有 5.

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

0

setTextUITextView方法不是UIImageView。现在,正如它在评论中提到的,cellText不是UITextView实例,它似乎是UIImageView实例,那么您试图从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]; 

这样,如果cellTextUITextView例如,它会初始化一个给你。

相关问题