您的位置:首页 > 移动开发 > IOS开发

【代码笔记】iOS-推荐收听,左右两个tableView

2016-06-16 09:17 537 查看
一,效果图。



二,工程图。



三,代码。

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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: