推荐收听(左右两个tableView,点击左侧的tableView,右侧的tableView内容会变化)

效果图:

代码:

.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
    //列表
    UITableView * _tableViewList;
    //显示内容
    UITableView * _tableViewMembers;
    NSMutableArray * ListArray;
    NSMutableArray * MembersArray;
}

@end

.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initTableView];

}
#pragma -mark -functions
-(void)initTableView
{
    //数据
    MembersArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil];
    ListArray = [[NSMutableArray alloc] initWithObjects:@"娱乐明星",
                 @"体育明星",
                 @"生活时尚",
                 @"财经",
                 @"科技网络",
                 @"文化出版",
                 @"汽车",
                 @"动漫",
                 @"游戏",
                 @"星座命理",
                 @"教育",
                 @"企业品牌",
                 @"酷站汇",
                 @"腾讯产品",
                 @"营销产品",
                 @"有趣用户",
                 @"政府机构",
                 @"公益慈善",
                 @"公务人员",
                 @"快乐女生",
                 @"公共名人",
                 @"花儿朵朵", nil];

    //列表tableView
    _tableViewList = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 416) style:UITableViewStylePlain];
    _tableViewList.delegate = self;
    _tableViewList.dataSource = self;
    [self.view addSubview:_tableViewList];

    //内容tableView
    _tableViewMembers = [[UITableView alloc] initWithFrame:CGRectMake(100, 0, 240, 416) style:UITableViewStylePlain];
    _tableViewMembers.delegate = self;
    _tableViewMembers.dataSource = self;
    [self.view addSubview:_tableViewMembers];

}
#pragma -mark -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == _tableViewList) {
        return ListArray.count;
    }else if(tableView == _tableViewMembers){
        return MembersArray.count;
    }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == _tableViewList) {
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];
        }

        cell.textLabel.text = [ListArray objectAtIndex:indexPath.row];
        return cell;
    }else {
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];
        }
        cell.textLabel.text = [MembersArray objectAtIndex:indexPath.row];
        return cell;

    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_tableViewList) {
        return 40;
    }else if (tableView==_tableViewMembers){
        return 80;
    }else{
        return 40;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _tableViewList) {
        //去服务器下载数据,同时_tableViewMembers刷新。
       [MembersArray removeAllObjects];
        MembersArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3", nil];
        [_tableViewMembers reloadData];

    }else if(tableView==_tableViewMembers){
        ;
    }
}
时间: 2024-07-29 13:44:15

推荐收听(左右两个tableView,点击左侧的tableView,右侧的tableView内容会变化)的相关文章

web实现点击左侧导航,右侧加载不同的网页(这种布局多用于后台管理系统)

(1)实现方法:采用ajax实现点击左侧菜单,右侧加载不同网页(在整个页面无刷新的情况下实现右侧局部刷新,用到ajax注意需要在服务器环境下运行,从HBuilder自带的服务器中打开浏览效果即可) (2)原理:ajax的局部刷新原理:通过.load()重新加载页面中的某一部分,巧妙的借助data-*的自定义属性来存储数据,点击的时候修改锚点,因为地址有变,所以刷新的时候仍然会保持当前的页面内容而不是切换到第一个. (3)适用场景:遇到ajax局部刷新的需求也有很多,有时候比较简单,当内容较少,适

iframe 点击左侧导航列表 右侧出现对应界面

HTML 代码结构如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <ul> <li><a href="http://www.w3school.com.c

点击左侧跳到右侧

效果图 JS部分 function moveOption(e1, e2){ try{ for(var i=0;i<e1.options.length;i++){ if(e1.options[i].selected){ var e = e1.options[i]; e2.options.add(new Option(e.text, e.value)); e1.remove(i); ii=i-1 } } } catch(e){}} HTML以及CSS部分 <form method="po

vue实现点击左侧菜单,右侧跟着显示隐藏

1 <template> 2 <div class="mainMaterial"> 3 <div class="chooseItem"> 4 <div class="navMenus"> 5 <ul> 6 <li v-for="(item,index) in items" :key="index" :class="{active:i

iOS开发-UITableViewCell(UICollectionViewItem)需要两个手指点击或者长按才可以选中,解决办法

今天写代码遇到一个特别诡异的问题,就是在我的cell中需要两个手指点击才可以选中 先介绍下我的视图结构ViewController->UITableView->自定义Cell 产生这样的原因是,我在ViewController.view上加了一个手势,导致了Cell不能点按的结果,把那个手势移除掉就好了 同理CollectionView也不可以加 虽然解决了问题,但是我还有个疑问,ViewController.view加的手势,为什么tableViewCell跟着混乱,如果加在tableVie

tableview 点击cell改变cell中的label.text的字体颜色,cell复用出现问题的解决方案2

关于Cell的复用问题,上次已经说了一种,但似乎那种方法不是最好的,所以说,今天下午根据别人提示,想到了此方法.还是老样子,可能不是最好的,但是实现了功能,至少比上次的要好一些. 题目要求:定义固定数据源,然后让tableview的行上各自显示第几行,然后点击选中的时候,字体颜色会变为红色,取消选中的时候字体变为黑色.然后最后的时候要输出选中的结果 解题思路:首先实现tableView的几个协议,然后定义一个模型,在模型中定义一个标识,然后通过点中的时候标识,然后判断标识解决Cell的复用. M

点击鼠标清除文本框中的内容

点击鼠标清除文本框中的内容:一般内容型的网站都有搜索功能,在默认状态下搜索框中都有默认的提示文本,例如“请输入要搜索的关键词”,但当搜索框获得焦点的时候,默认的提示文本内容会被清空,下面就简单介绍以下如何实现此功能,代码实例如下: <!<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="

PHP+Mysql+easyui点击左侧tree菜单对应表名右侧动态生成datagrid加载表单数据(二)

关于tree菜单生成,参考我的另一篇博文地址tree 菜单 实现功能:点击左侧tree菜单中的table,右侧通过datagrid加载出该表对用的所有数据 难点:获取该表的所有列名,动态生成datagrid,并加载数据 解决办法: 使用tree菜单的onClick事件: $('#tree').tree( { url:'tree_getData.php', onClick:function(node){ //判断点击的节点是否是子节点是子节点就创建datagrid,否则就return打开这个节点

七种实现左侧固定,右侧自适应两栏布局的方法

总结一下左边固定,右边自适应的两栏布局的七种方法.其中有老生常谈的float方法,BFC方法,也有CSS3的flex布局与grid布局.并非所有的布局都会在开发中使用,但是其中也会涉及一些知识点.关于最终的效果,可以查看这里 常用的宽度自适应的方法通常是利用了block水平的元素宽度能随父容器调节的流动特性.另外一种思路是利用CSS中的calc()方法来动态设定宽度.还有一种思路是,利用CSS中的新型布局flex layout与grid layout. 首先创建基本的HTML布局和最基本的样式.