// AppDelegate.m
#import "ViewController.h"
ViewController *vc = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor grayColor];
// ViewController.m
#import "MainViewController.h"
//---------------------------
//标题
self.title = @"登录";
//标签:用户名
UILabel *lab1 = [[UILabel alloc]initWithFrame:CGRectMake(48, 100, 66, 44)];
lab1.text = @"用户名:";
lab1.textColor = [UIColor blackColor];
[self.view addSubview:lab1];
//标签:密码
UILabel *lab2 = [[UILabel alloc]initWithFrame:CGRectMake(50, 180, 66, 44)];
lab2.text = @"密码:";
lab2.textColor = [UIColor blackColor];
[self.view addSubview:lab2];
//文本框账号
UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 44)];
text1.borderStyle = UITextBorderStyleRoundedRect;
text1.secureTextEntry = NO;
[self.view addSubview:text1];
//密码文本框
UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectMake(100, 180, 200, 44)];
text2.borderStyle = UITextBorderStyleRoundedRect;
text2.secureTextEntry = YES;
[self.view addSubview:text2];
//登录
UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
but.frame = CGRectMake(150, 250, 100, 44);
[but setTitle:@"登录" forState:UIControlStateNormal];
but.backgroundColor = [UIColor blackColor];
//添加事件
[but addTarget:self action:@selector(Method) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:but];
//===================
//点击登录跳转
-(void)Method
{
MainViewController *main = [[MainViewController alloc] init];
[self presentViewController:main animated:YES completion:nil];
}
// MainViewController.h 继承 UITabBarController
// MainViewController.m
#import "oneViewController.h"
#import "twoViewController.h"
#import "threeViewController.h"
#import "fourViewController.h"
//=============================
oneViewController *one = [[oneViewController alloc] init];
twoViewController *two = [[twoViewController alloc] init];
threeViewController *three = [[threeViewController alloc] init];
fourViewController *four = [[fourViewController alloc] init];
UINavigationController *navOne = [[UINavigationController alloc] initWithRootViewController:one];
UINavigationController *navTwo = [[UINavigationController alloc] initWithRootViewController:two];
UINavigationController *navThree = [[UINavigationController alloc] initWithRootViewController:three];
UINavigationController *navFour = [[UINavigationController alloc] initWithRootViewController:four];
UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"我的音乐" image:[UIImage imageNamed:@"首页.png"] tag:1 ];
UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"音乐馆" image:[UIImage imageNamed:@"首页.png"] tag:1 ];
UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"发现" image:[UIImage imageNamed:@"首页.png"] tag:1 ];
UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"更多" image:[UIImage imageNamed:@"首页.png"] tag:1 ];
navOne.tabBarItem = item1;
navTwo.tabBarItem = item2;
navThree.tabBarItem = item3;
navFour.tabBarItem = item4;
self.viewControllers = @[navOne,navTwo,navThree,navFour];
//====================================================================
// threeViewController.m 分区表格
//点击音乐圈跳转
#import "threeNextViewController.h"
<UITableViewDelegate,UITableViewDataSource>
{
UITableView *theTableView;
NSMutableArray *arr1,*arr2,*arr3,*arr4;
}
//=======括号内==========
//标题
self.title = @"发现";
//初始化
theTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
//数组1
arr1 = [NSMutableArray arrayWithObjects:@"音乐圈", nil];
//数组2
arr2 = [NSMutableArray arrayWithObjects:@"猜你喜欢",@"听歌识曲",@"身边流行", nil];
//数组3
arr3 = [NSMutableArray arrayWithObjects:@"歌手",@"明星部落", nil];
//数组4
arr4 = [NSMutableArray arrayWithObjects:arr1,arr2,arr3, nil];
//签协议
theTableView.delegate = self;
theTableView.dataSource = self;
//添加到视图
[self.view addSubview:theTableView];
//右上按钮
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"分类.png"] style:UIBarButtonItemStyleDone target:self action:@selector(tiao)];
//=======括号外==========
//右上角按钮点击事件
-(void)tiao
{
NSLog(@"我有添加事件,我被点击了一下😆");
}
//分区几行
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return arr4.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr4[section]count];
}
//tablecell表格
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
}
NSArray *arr5 = arr4 [indexPath.section];
NSString *str = [arr5 objectAtIndex:indexPath.row];
//分区每行图片
cell.imageView.image = [UIImage imageNamed:@"分类"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = str;
return cell;
}
//跳转
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
threeNextViewController *theNVC = [[threeNextViewController alloc] init];
[self.navigationController pushViewController:theNVC animated:YES];
}
网友评论