2010-01-21 10 views
0

我只有1的tableView類,但4個細胞類。我將相同的tableView添加到應用程序中存在的所有viewController。區別在於單元格的類型(準確地說,類)。我想根據的viewController其中的tableView存在更改類細胞。另外,單元格的內容視圖是在單元類的另一個子類中繪製的。請提供一個解決方案或方法來實現此功能。 提前致謝。變化類TableViewCell的,其中的tableView是本

+1

您的意思是說,不同控制器中的所有tableview都使用相同的委託和數據源類嗎? – Vladimir 2010-01-21 10:29:53

+0

是所有viewControllers初始化相同TableViewController和使用[self.view addSubview:TableViewController.view]中的tableView增加。數據源是在TableViewController,但代表的是初始化的TableViewController的的viewController。 – Nishit 2010-01-21 11:09:11

回答

1

你也許應該使用每個視圖控制器不同的表視圖(如果你沒有的話)。

通常,您還可以爲每個表視圖使用不同的數據源/委託(例如,您可以使用每個視圖控制器)。但是,如果您必須對所有四個表視圖使用相同的類作爲數據源/委託,tableView:cellForRowAtIndexPath:(和其他委託方法)會爲您提供表視圖作爲第一個參數,因此您可以返回正確的像這樣的單元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView == myTableViewOne) { 
     // dequeue or allocate/init and configure/return the cell for the first table view here 
    } else if (tableView == myTableViewTwo) { 
     // dequeue or allocate/init and configure/return the cell for the second table view here 
    } else if (tableView == myTableViewThree) { 
     // dequeue or allocate/init and configure/return the cell for the third table view here 
    } else { 
     // dequeue or allocate/init and configure/return the cell for the fourth table view here 
    } 
} 
1

詢問的tableView爲它的使用NSObjects -class方法類的名稱,並使用它在使用什麼樣細胞類決定。

相關問題