2012-05-24 67 views
2

我想在UIViewController中以編程方式創建2個UITableView。我有2個NSMutableArray是* firstTableDatas和* secondTableDatas的數據。我可以管理以編程方式創建一個UITableView的,但是當它成爲2然後我很困惑什麼將是2的UITableView爲代表的返回值:如何以編程方式在UIViewController中創建多個UITableView?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
} 

以及我如何在2個單獨的UITableView中加載數據。

在此先感謝。

+0

試試這個你找到示例代碼與2種不同的方法做到這一點的完整解釋:請參閱我的答案http://stackoverflow.com/a/11789681/846372 – Soniya

回答

4

使用

if(tableView ==Firsttable) 
{ 
... 
} 
else 
{ 
... 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
... 
} 
1

給DIFF標籤到兩個的tableView和有標籤的基地做所需要的功能

例如:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
     if(tableView.tag==1) 
     { 
      return 100; 
     } 
     else if(tableView.tag==2) 
     { 
      return 50; 
     } 
     return 40; 
} 
2

您可以檢查l IKE如下:

if(tableView ==firstTableDatas) 
{ 
    //Code related to First Table 
} 
else if(tableView ==secondTableDatas) 
{ 
    //Code related to Second Table 
} 

它將在的UITableViewDelegate方法的工作。

快樂編碼。

相關問題