登錄->標(biāo)簽控制器->分區(qū)表格


//? 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"

//---------------------------

//標(biāo)題

self.title = @"登錄";

//標(biāo)簽:用戶名

UILabel *lab1 = [[UILabel alloc]initWithFrame:CGRectMake(48, 100, 66, 44)];

lab1.text = @"用戶名:";

lab1.textColor = [UIColor blackColor];

[self.view addSubview:lab1];

//標(biāo)簽:密碼

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];

//===================

//點擊登錄跳轉(zhuǎn)

-(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:@"發(fā)現(xiàn)" 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? 分區(qū)表格

//點擊音樂圈跳轉(zhuǎn)

#import "threeNextViewController.h"

<UITableViewDelegate,UITableViewDataSource>

{

UITableView *theTableView;

NSMutableArray *arr1,*arr2,*arr3,*arr4;

}

//=======括號內(nèi)==========

//標(biāo)題

self.title = @"發(fā)現(xiàn)";

//初始化

theTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];

//數(shù)組1

arr1 = [NSMutableArray arrayWithObjects:@"音樂圈", nil];

//數(shù)組2

arr2 = [NSMutableArray arrayWithObjects:@"猜你喜歡",@"聽歌識曲",@"身邊流行", nil];

//數(shù)組3

arr3 = [NSMutableArray arrayWithObjects:@"歌手",@"明星部落", nil];

//數(shù)組4

arr4 = [NSMutableArray arrayWithObjects:arr1,arr2,arr3, nil];

//簽協(xié)議

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(@"我有添加事件,我被點擊了一下??");

}

//分區(qū)幾行

-(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];

//分區(qū)每行圖片

cell.imageView.image = [UIImage imageNamed:@"分類"];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

cell.textLabel.text = str;

return cell;

}

//跳轉(zhuǎn)

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

threeNextViewController *theNVC = [[threeNextViewController alloc] init];

[self.navigationController pushViewController:theNVC animated:YES];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容