iOS程序在单个UIViewController中使用多个UITableView [英] iOS program to use multiple UITableView in a single UIViewController

查看:115
本文介绍了iOS程序在单个UIViewController中使用多个UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在故事板中的单个segue中实现3个表。
当选择一个表时,它将取消隐藏另一个表的视图,同样一个表。
以下代码我用于一个表,每个表的单元格格式不同,行也有所不同。那么我如何通过编码为每个表设置不同的行数来区分每个表,等等?

I am trying to implement 3 tables in a single segue in a storyboard. When one table is selected it will unhidden a view with another table and likewise one more. The following code i have used for one table the cell format of each table is different and rows also vary. So how can i DIFFERENTIATE between each table by coding to set different number of rows for each table and so on?

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell2";
    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell1==nil)
{
    cell1=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
    temp=[array objectAtIndex:indexPath.row];
    UILabel *Label1 = (UILabel *)[cell1 viewWithTag:4];
    Label1.text = temp.Title;
    UILabel *Label2 = (UILabel *)[cell1 viewWithTag:6];
    Label2.text = temp.Title;
    UITextField *textfield1 = (UITextField *)[cell1 viewWithTag:5];
    textfield1.text =temp.description;
    UILabel *Label3 = (UILabel *)[cell1 viewWithTag:7];
    Label3.text = temp.Title;
    return cell1;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.showlist=[[ShowList alloc]initWithNibName:@"ShowList" bundle:nil];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    ShowlistIndex=indexPath.row;
    _secondview.hidden=NO;
}


推荐答案

你应该声明你的 tableViews in .h file。

You should declare your tableViews in .h file.

@property (weak, nonatomic) UITableView *firstTableView;
@property (weak, nonatomic) UITableView *secondTableView;
@property (weak, nonatomic) UITableView *thirdTableView;

然后所有委托方法都有变量,指向女巫对象调用此方法,因此您可以检查:

And then all the delegate methods have variable with pointing witch object call this method, so you can check:

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView == self.firstTableView)
       return  3;
   else if(tableView == self.secondTableView)
       return 4;
   else if(tableView == self.thirdTableView)
      return 100;
}

其他委托方法的工作方式相同。

The other delegate methods work in the same way.

这篇关于iOS程序在单个UIViewController中使用多个UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆