2010-10-26 46 views
0

我有一個ViewController需要使用2個UITableViews。
1總是顯示,而另一個會在您點擊視圖上的按鈕後顯示爲彈出窗口。具有多個數據源的UITableView

通常,我將委託和數據源設置爲文件的所有者。但是,由於1個UITableViews在彈出窗口中,所以我不確定如何最好地解決這個問題。 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;(UITableView * *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

請指教。

感謝,
三通

回答

7

你應該在你的控制器聲明爲表視圖的實例變量:

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> 
{ 
    UITableView *mainTableView; 
    UITableView *popupTableView; 
} 

在每個數據源或委託方法,您可以檢查哪些表視圖是通過來電者:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(tableView == mainTableView) 
    { 
    // Code to create and return a main table view cell 
    } 
    else if(tableView == popupTableView) 
    { 
    // Code to create and return a popup table view cell 
    } 
} 
+0

我剛剛打完全相同的東西。 +1 – 2010-10-26 19:13:07

相關問題