2012-07-28 91 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例如,它會初始化一個給你。

相關問題