2013-01-10 20 views
1

我已經分類UITableViewCell類,一個工程,另一個不工作,我不知道爲什麼。爲什麼我的UITableViewCell的子類聲稱它是cellForRowAtIndexPath函數中的UIView類?

這是引發錯誤的功能:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { 

    NSString *type = [object objectForKey:@"type"]; 

    static NSString *CellIdentifier1 = @"Cell1"; 
    static NSString *CellIdentifier2 = @"Cell2"; 

    if ([type isEqualToString:@"quote"]) { 

     QuoteCell *cell = (QuoteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 

     if (cell == nil) { 
      cell = [[QuoteCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1]; 
     } 
     cell.contentText.text = [object objectForKey:self.textKey]; 
     NSDate *date = object.createdAt; 
     cell.datetimeLabel.text = [NSDate stringForDisplayFromDate:date]; 
     return cell; 
    } 
    else if([type isEqualToString:@"photo"]) 
    { 
     TestCell *cell = (TestCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 

     if (cell == nil) { 
      cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2]; 
     } 
     return cell; 
    } 

    return nil; 

} 

對於我想不出一個原因,UITableViewCell,該TestCell類的子類之一,他表示,這是一個UIView代替的UITableViewCell?我subclassed從UITableViewCell兩個班完全一樣,我認爲但QuoteCell作品,並說它的一個UITableViewCellTestCell沒有,並說它的一個UIView

以下是錯誤 -

終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: ' - [UIView的setTableViewStyle:]:無法識別的選擇發送到實例0x96b7b70'

什麼想法?

在我被困在這個問題上幾個小時後,我在發佈後10分鐘就發現它。這與我如何創建UITableViewCells有關。我創建的類擴展UITableViewCell和TestCell.m中的initWithStyle函數我從MainBundle中獲取nibArray,但因爲我在單元格中有一個UIImageView,所以單元格本身的索引實際上發生了變化,所以我必須更改索引以查找筆尖在單元格本身的數組中。感謝所有已經回覆的人。

+0

繼續併爲所有例外設置一個斷點。在執行execption的那一刻,您會看到相同的錯誤消息以及它所在的代碼行。在看到所有信息之前,您可能需要按2次或3次繼續。然後用這行代碼返回給我們,我們試圖找出爲什麼當一個UITableViewCell被期望時(最有可能)UIView被訪問。 –

+1

測試單元是UIVIew的一個子類。所以對於Uiview,你不能設置tableviewstyle –

+0

在這個問題上停留了幾個小時後,我在發佈10分鐘後發現了它。這與我如何創建UITableViewCells有關。我創建的類擴展UITableViewCell和TestCell.m中的initWithStyle函數我從MainBundle中獲取nibArray,但因爲我在單元格中有一個UIImageView,所以單元格本身的索引實際上發生了變化,所以我必須更改索引以查找筆尖在單元格本身的數組中。謝謝赫爾曼和烏瑪。 – durbin

回答

0

例外-[UIView setTableViewStyle:]不在UITableViewCell上,因爲setTableViewStyle:UITableView方法。所以你可能想看看你是如何創建tableView的。

相關問題