Iphone 是否可以在UIView中添加两个tableView?

Iphone 是否可以在UIView中添加两个tableView?,iphone,objective-c,uitableview,uiviewcontroller,Iphone,Objective C,Uitableview,Uiviewcontroller,我在应用程序中使用了两个UItableView。我将其委托和数据源设置为文件的所有者。 在实施部分,我尝试了: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView=tableView1) { return [tableArr count]; } if (tableView=tableView2) { return [ta

我在应用程序中使用了两个UItableView。我将其委托和数据源设置为文件的所有者。 在实施部分,我尝试了:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView=tableView1) 
{
return [tableArr count];
}
if (tableView=tableView2) 
{
    return [tableArr count];
}
}

方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (tableView==tableView1) 
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        }

        cell.textLabel.text=[tableArr objectAtIndex:indexPath.row];
        return cell;

    }
    if (tableView==tableView2) 
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        }

        cell.textLabel.text=[tableArr objectAtIndex:indexPath.row];
        return cell;

    }


我也试着调用tableView,比如tableView1和tableView2,但它显示的是空白表。那么,是否可以在UIView中添加到tableView

这是可能的,但我想

    if (tableView=tableView1) 
{
return [tableArr count];
}
if (tableView=tableView2) 
{
    return [tableArr count];
}
这个代码应该在

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
而不是在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
如果您是从Interface builder中添加的,您是否已将引用IBoutlet设置为相应的tableview

使用


[tableView isEqual:tableView1]/*而不是*/if(tableView=tableView1

这是可能的,但我想

    if (tableView=tableView1) 
{
return [tableArr count];
}
if (tableView=tableView2) 
{
    return [tableArr count];
}
这个代码应该在

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
而不是在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
如果您是从Interface builder中添加的,您是否已将引用IBoutlet设置为相应的tableview

使用


[tableView isEqual:tableView1]/*而不是*/if(tableView=tableView1

您实际上是在做赋值而不是比较(
=
vs
=
),因此它总是第一次返回。同时确保
tableView1
tableView2
实际上是非零对象(IBOutlet连接或适当的
init
方法应该可以工作)。

您实际上是在执行赋值而不是比较(
=
vs
=
),因此它总是第一次返回。同时确保
tableView1
tableView2
实际上是非零对象(IBOutlet连接或适当的
init
方法应该有效)。

正如Eimantas所说,你应该尝试比较,而不是分配,尝试这样做,并确保你在
cellForRowAtIndexPath:

  if (tableView==tableView1) 
{
return [tableArr count];
}
if (tableView==tableView2) 
{
    return [tableArr count];
}

正如艾曼塔斯所说,你应该尝试比较而不是分配,尝试一下,并确保你在
cellforrowatinexpath:

  if (tableView==tableView1) 
{
return [tableArr count];
}
if (tableView==tableView2) 
{
    return [tableArr count];
}


是的,我已经将引用IBoutlet添加到各自的TableView中了是的,我已经将引用IBoutlet添加到各自的TableView中了
tableArr
是什么样子的?tableArr=[[NSMutableArray alloc]initWithObjects:@“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、nil];警报按钮点击与表委托方法有什么关系。另外-请阅读Mihir的答案。耶..读了这篇文章,它就这样工作了,但仍然不工作,但是如果我通过删除所有if条件工作,那么它就工作了,并且只显示一个表
tableArr
看起来像什么?tableArr=[[NSMutableArray alloc]initWithObjects:@"1,"2,"3,"4,"5,"6,"7,"8,"9,"10,无];警报按钮单击与表委托方法有什么关系。另外-请阅读Mihir的答案。耶..阅读该答案并以这种方式工作,但仍然不工作,但如果我通过删除所有if条件工作,那么它工作并仅显示一个表为什么使用UITableViewCell*单元格=[tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];对于两个表?请检查行数是否返回正确,是否可以检查cellForRow中的数据?否,未找到值。但如果我通过删除所有if条件来工作,则它工作并仅显示一个表。请设置断点并查看执行情况,然后您将了解呼叫goeswhy正在使用UITableViewCell*cell=[tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];对于两个表?请检查行数是否返回正确,是否可以检查cellForRow中的数据?否,未找到值。但如果我通过删除所有if条件来工作,则它工作并仅显示一个表。请设置断点并查看执行情况,然后您将了解通话结束