2012-12-31 53 views
0

我有一個SearchDisplayController和TableView中的tableView財產申報或連桿

在.H視圖(搜索查看):

@property (nonatomic, retain) IBOutlet UITableView *tableView; 

我聯繫這的.xib文件中的TableView:> see linkages here

然後在cellforrow:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 


if(listGoal){ 

    Goal *goalz = nil; 

    if (tableView == self.searchDisplayController.searchResultsTableView) 
    { 
     goalz = [self.filteredListContent objectAtIndex:indexPath.row]; 
     cell.textLabel.text = goalz.goalNaam; 
    } 
    else 
    { 

     goalz = [arr objectAtIndex:indexPath.row]; 
     cell.textLabel.text = goalz.goalNaam; 
     cell.detailTextLabel.text = goalz.goalBeschrijving; 
    } 
} 

我測試是否需要filteredListContent或原始數組arr。 (因爲我使用的是SearchDisplayController) 哪個工作正常。

在另一種方法,

if (tableView == self.searchDisplayController.searchResultsTableView) 

不工作了,所以我嘗試使用

self.tableView 

但這也不工作,

(UITableView *)tableView 

不工作無論是。 我知道我的財產聲明或鏈接有問題,但是出了什麼問題?

+0

我認爲searchTableView只有在屏幕上顯示時纔可用。 哪種方法不適合你? –

+0

在一個自定義方法中,在同一個類中。我怎樣才能以正確的方式調用tableview? – Fuzej

回答

1

您可以在您的自定義方法中訪問搜索視圖的一種方法是在您獲取搜索視圖時保留強大的引用。但我不確定它是否會在多個搜索中有效。

也許你可以只設置一個BOOL變量並在你的自定義方法中使用它。我想你不能在自定義方法中訪問搜索視圖。

+0

我改變了「tableView == self.searchDisplayController.searchResultsTableView」BOOLEAN「過濾」,現在它的工作。但是tableview應該是可訪問的,不是嗎.. – Fuzej

+0

是的,tableView應該可以在你的自定義方法中訪問,如果它的成員變量和你有一個可用的有效引用。 –