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