设为首页 加入收藏

TOP

【代码笔记】iOS-推荐收听,左右两个tableView(一)
2017-10-13 10:23:03 】 浏览:3819
Tags:代码 笔记 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:UITableViewCellStyleva lue1 reuseIdentifier:@"ID"];
        }
        
        cell.textLabel.text = [ListArray objectAtIndex:indexPath.row];
        return cell;
    }else {
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleva lue1 reuseIdentifier:@"ID"];
        }
        cell.textLabel.text = [MembersArray objectAtIndex:indexPath.row];
        return cell;
        
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS 10 都有什么改变? 下一篇GCD定时器

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目