zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-推荐收听,左右两个tableView

    一,效果图。

    二,工程图。

    三,代码。

    RootViewController.h

    复制代码
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    <UITableViewDelegate,UITableViewDataSource>
    {
        //列表
        UITableView * _tableViewList;
        //显示内容
        UITableView * _tableViewMembers;
        NSMutableArray * ListArray;
        NSMutableArray * MembersArray;
    }
    
    @end
    复制代码

    RootViewcontroller.m

    复制代码
    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (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){
            ;
        }
    }
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    复制代码
     
     
  • 相关阅读:
    无限极分类,递归分类
    foreach加循环体与不加循环体的区别
    图片base64上传时可能遇到的问题
    php(curl请求)测试接口案例
    PHP取得json前面有乱码(去除文件头部BOM)
    PHP计算连续签到天数以及累计签到天数
    原生端与服务器通过sessionid实现session共享以及登录验证
    php安装xunserch
    ROS学习(二)运行keyboard
    ROS学习(一)Ros 中使用kinect
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5589835.html
Copyright © 2011-2022 走看看