0
我正在嘗試將2 UITableView
添加到我的UIViewController
。我需要爲這些表添加不同的數據。將數據添加到2個表
這是我加入2個表(這個代碼加入到viewDidLoad方法)
self.tableView2 = [[UITableView alloc] initWithFrame:CGRectMake(0,140,292,250) style:UITableViewStylePlain] ;
self.tableView2 .dataSource = self;
self.tableView2 .delegate = self;
那麼其他表
self.tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,100) style:UITableViewStylePlain] ;
self.tableView1 .dataSource = self;
self.tableView1 .delegate = self;
定義如下部分的數量;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView==tableView1) {
return 12;
}
else { return 10; }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ...... more code here
if (tableView == self.tableView1) {
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[email protected]"Cells .... ";
}
else{
// the remaining code here.. i am populating the cell as in the previous `IF` condition.
}
}
問題是,我只得到第一個表填充,而不是第二個表。爲什麼是這樣?我該如何解決這個問題?
編輯: 我還添加以下代碼,希望作出改變
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView==tableView1) {
return 1;
}
else if (tableView==tableView2) { return 0; }
else { return 0; }
}
您是如何的tableViews添加到上海華? – vikingosegundo 2011-12-25 15:07:20
呃..我根據上面的代碼做了。並顯示出來。我無法填充它。需要幫助! – Illep 2011-12-25 15:08:54
肯定可以確定你在else部分返回任何東西嗎? – 2011-12-25 15:18:21