无标题文章

//// LeftMenuViewController.m// StarrySky//// Created by RickyWei on 2017/10/30.// Copyright © 2017年 BW. All rights reserved.//#import "LeftMenuViewController.h"#import "LoginViewController.h"#import "PersonViewController.h" //个人信息控制器#import "CollectionViewController.h" //我的收藏#import "AboutUsViewController.h" //关于我们@interface LeftMenuViewController (){

NSArray *_tableDatas;//表格数据

}

//头像视图

@property(nonatomic,strong)UIImageView *headImgView;

//账号label

@property(nonatomic,strong)UILabel *accountLabel;

//表格

@property(nonatomic,strong)UITableView *table;

//登录视图控制器

@property(nonatomic,strong)LoginViewController *loginVC;

@end

@implementation LeftMenuViewController

#pragma mark ------- 控制器实例化 ----------

-(LoginViewController *)loginVC{

if (!_loginVC) {

_loginVC = [[LoginViewController alloc]init];

}

return _loginVC;

}

#pragma mark ------- 控件实例化 ----------

//头像视图

-(UIImageView *)headImgView{

if (!_headImgView) {

_headImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, FIT_X(80), FIT_X(80))];

_headImgView.center = CGPointMake(SCREEN_W/4+FIT_X(50), FIT_Y(104));

_headImgView.clipsToBounds = YES;

_headImgView.layer.cornerRadius = FIT_X(40);

_headImgView.image = [UIImage imageNamed:@"40"];

_headImgView.userInteractionEnabled = YES;

_headImgView.contentMode =  UIViewContentModeScaleAspectFill;

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headImgDidHandle:)];

[_headImgView addGestureRecognizer:tap];

}

return _headImgView;

}

//账号标签

-(UILabel *)accountLabel{

if (!_accountLabel) {

_accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, FIT_X(300), FIT_Y(30))];

_accountLabel.center = CGPointMake(self.headImgView.center.x, self.headImgView.center.y + self.headImgView.frame.size.height / 2 + FIT_Y(15) + FIT_Y(20));

_accountLabel.textAlignment = NSTextAlignmentCenter;

_accountLabel.text = @"18911121441";

_accountLabel.textColor = [UIColor whiteColor];

_accountLabel.font = [UIFont systemFontOfSize:18.];

}

return _accountLabel;

}

//选项表格

-(UITableView *)table{

if (!_table) {

_table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, FIT_X(300), 200) style:UITableViewStylePlain];

_table.rowHeight = 50;

_table.center = CGPointMake(self.headImgView.center.x, self.accountLabel.center.y + self.accountLabel.frame.size.height / 2 + 100 + FIT_Y(20));

_table.scrollEnabled  = NO;

_table.backgroundColor = [UIColor clearColor];

_table.dataSource = self;

_table.delegate = self;

}

return _table;

}

#pragma mark - --- UITableViewDelegate ----

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

switch (indexPath.row) {

case 0:  //个人信息

[self headImgDidHandle:nil];

break;

case 1:  //我的收藏

{

if ([[UserDataBase shaerDataBase]userHadLogin]) {

CollectionViewController *collVC = [[CollectionViewController alloc]initWithTag:BaseViewControllerTag_Left];

UINavigationController *collNav = [[UINavigationController alloc]initWithRootViewController:collVC];

collVC.navigationItem.title = @"我的收藏";

[self presentViewController:collNav animated:YES completion:nil];

}

else

{

[self presentViewController:self.loginVC animated:YES completion:nil];

}

}

break;

case 2:  //关于我们

{

AboutUsViewController *usVC = [[AboutUsViewController alloc]initWithTag:BaseViewControllerTag_Left];

UINavigationController *usNav = [[UINavigationController alloc]initWithRootViewController:usVC];

usVC.navigationItem.title = @"关于我们";

[self presentViewController:usNav animated:YES completion:nil];

}

break;

case 3:  //退出登录

{

//底层数据库业务退出

[[UserDataBase shaerDataBase]logOut];

//更新菜单视图UI

[self updateAllUI];

//发出一个退出登录的通知

[[NSNotificationCenter defaultCenter] postNotificationName:LOGOUT_NOTIFICATION_NAME object:nil];

}

break;

default:

break;

}

}

#pragma mark ----UITableViewDataSource ----

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

if ([[UserDataBase shaerDataBase] userHadLogin]) {

return _tableDatas.count;

}

else

{

return _tableDatas.count - 1;

}

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *identifier =@"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil)

{

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

}

cell.backgroundColor = [UIColor clearColor];

cell.textLabel.textColor = [UIColor whiteColor];

cell.textLabel.font = [UIFont systemFontOfSize:18];

cell.textLabel.textAlignment = NSTextAlignmentCenter;

cell.textLabel.text = _tableDatas[indexPath.row];

//点击不变色

cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;

}

#pragma mark ------触发事件 -----

//头像点击触发方法

-(void)headImgDidHandle:(id)sender{

NSLog(@"点击了头像");

if ([[UserDataBase shaerDataBase]userHadLogin]) {

//有用户登录,进入个人信息视图

PersonViewController *personVC = [[PersonViewController alloc]initWithTag:BaseViewControllerTag_Left];

UINavigationController *personNav = [[UINavigationController alloc]initWithRootViewController:personVC];

personVC.navigationItem.title = @"个人信息";

[self presentViewController:personNav animated:YES completion:nil];

}

else

{

//没有用户登录,进入登录视图

[self presentViewController:self.loginVC animated:YES completion:nil];

}

}

#pragma mark -------- loadView -------

-(void)loadView{

[super loadView];

[self.view addSubview:self.headImgView];

[self.view addSubview:self.accountLabel];

[self.view addSubview:self.table];

}

#pragma mark -------- View Load /Appear -------

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

_tableDatas = @[@"个人信息",@"我的收藏",@"关于我们",@"退出登录"];

[self.table reloadData];

}

-(void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];

[self updateAllUI];

}

//  更新所有控件的UI显示

-(void)updateAllUI{

[self.table reloadData];

//没有用户登录

if (![[UserDataBase shaerDataBase]userHadLogin]) {

//头像显示默认图片

self.headImgView.image = [UIImage imageNamed:@"40"];

//账号label不显示

self.accountLabel.hidden = YES;

}

else

{

//有用户登录的情况下

//获取登录人信息

User *u  = [[UserDataBase shaerDataBase]getCurrentLoginUser];

//显示账号

self.accountLabel.hidden = NO;

self.accountLabel.text = u.phone;

//头像设置

if (u.headImg == nil) {

//头像显示默认图片

self.headImgView.image = [UIImage imageNamed:@"40"];

}

else

{//设置头像 显示头像

UIImage *img = [[UIImage alloc]initWithContentsOfFile:[DOCUMENT_PATH stringByAppendingPathComponent:u.headImg]];

self.headImgView.image = img;

}

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,185评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,652评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,524评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,339评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,387评论 6 391
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,287评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,130评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,985评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,420评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,617评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,779评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,477评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,088评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,716评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,857评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,876评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,700评论 2 354

推荐阅读更多精彩内容