302 lines
11 KiB
Objective-C
302 lines
11 KiB
Objective-C
//
|
|
// LeftViewController.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 15/9/27.
|
|
// Copyright © 2015年 imac. All rights reserved.
|
|
//
|
|
|
|
#import "LeftViewController.h"
|
|
|
|
#import "SetViewController.h"
|
|
#import "CenterViewController.h"
|
|
#import "ConnectWifiViewController.h"
|
|
#import "SaySomethingViewController.h"
|
|
|
|
#import "ICSDrawerController.h"
|
|
#import "CenterViewController.h"
|
|
#import "leftCell.h"
|
|
#import "LeftCellmodel.h"
|
|
#import "InfoViewController.h"
|
|
#import "UIImageView+WebCache.h"
|
|
#import "UIButton+WebCache.h"
|
|
#import "DeviceModel.h"
|
|
#import "ScanViewController.h"
|
|
#import "AppDelegate.h"
|
|
#import "BookViewController.h"
|
|
#import "UMComLoginDelegate.h"
|
|
#import "PushMasssageWebViewController.h"
|
|
#import "UMComShowToast.h"
|
|
#define UpdateUserProfileSuccess @"update user profile success!"
|
|
@interface LeftViewController ()<UMComLoginDelegate>
|
|
//@property(nonatomic,strong)UIImageView*imageView;
|
|
@property(nonatomic,strong)UIButton *nameLael;
|
|
@property(nonatomic,strong)UIButton*iconImageButton;
|
|
@property(nonatomic,strong)ICSDrawerController*ics;
|
|
|
|
@end
|
|
|
|
@implementation LeftViewController
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"leftblack.png"]]];
|
|
AppDelegate*myDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
|
|
|
|
self.view.backgroundColor = COLOR_MIAN;
|
|
|
|
|
|
_iconImageButton=[UIButton buttonWithType:UIButtonTypeSystem];
|
|
[_iconImageButton addTarget:self action:@selector(tappushInfo) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
_iconImageButton.frame=CGRectMake((kScreenSize.width - 60)/2 -100*myDelegate.autoSizeScaleY/2, 30*myDelegate.autoSizeScaleY, 100*myDelegate.autoSizeScaleX, 100*myDelegate.autoSizeScaleY);
|
|
[self.view addSubview:_iconImageButton];
|
|
_iconImageButton.layer.masksToBounds=YES;
|
|
_iconImageButton.layer.cornerRadius=_iconImageButton.bounds.size.width*0.5;
|
|
_iconImageButton.layer.borderColor=[UIColor whiteColor].CGColor;
|
|
|
|
|
|
_nameLael=[[UIButton alloc]initWithFrame:CGRectMake((kScreenSize.width-60)/2 - 100, 135*myDelegate.autoSizeScaleY, 200, 30)];
|
|
|
|
[_nameLael setTitleColor:COLOR_LABEL_TITLE forState:UIControlStateNormal];
|
|
[_nameLael addTarget:self action:@selector(tappushInfo) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
[self.view addSubview:self.nameLael];
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self UserImageView];
|
|
});
|
|
|
|
[self creatTableView];
|
|
[self initData];
|
|
|
|
}
|
|
|
|
-(void)initData{
|
|
self.tileArr=@[@"爱鱼圈",@"我的智能鱼缸",@"观赏鱼图鉴",@"设置",@"扫一扫",@"我有话说",@"购买摄像头"];
|
|
self.headimgeArr=@[@"community_left",@"fish_left",@"refer_book",@"set_left",@"scan_left",@"say_left",@"left_camerashop"];
|
|
}
|
|
|
|
// 头像
|
|
-(void)UserImageView{
|
|
|
|
UserModel*userModel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
|
|
NSString*fullpath=[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"avatar.png"];
|
|
UIImage*saveImage=[[UIImage alloc]initWithContentsOfFile:fullpath];
|
|
if (saveImage==nil) {
|
|
// 这里注意 <null>
|
|
if ([userModel.userImg isKindOfClass:[NSNull class]]) {
|
|
//int i = (arc4random()%7) + 1;// 设置随机头像
|
|
int i = 1;
|
|
[_iconImageButton setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]] forState:UIControlStateNormal];
|
|
|
|
|
|
}else{
|
|
if ([userModel.userImg isEqualToString:@""]) {
|
|
|
|
UIImage*User=[UIImage imageNamed:@"userIcon1"];
|
|
|
|
[_iconImageButton setBackgroundImage:User forState:UIControlStateNormal];
|
|
}else{
|
|
|
|
// int i = 1;
|
|
// [_iconImageButton setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]] forState:UIControlStateNormal];
|
|
|
|
NSString*str=[NSString stringWithFormat:@"%@%@",kGetIconUrl,userModel.userImg];
|
|
[_iconImageButton sd_setBackgroundImageWithURL:[NSURL URLWithString:str] forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
|
|
NSString*str=[NSString stringWithFormat:@"%@%@",kGetIconUrl,userModel.userImg];
|
|
if ([str isEqualToString:kGetIconUrl]) {
|
|
//int i = (arc4random()%7) + 1;// 设置随机头像
|
|
int i = 1;
|
|
[_iconImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]] forState:UIControlStateNormal];
|
|
|
|
}else{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[_iconImageButton sd_setBackgroundImageWithURL:[NSURL URLWithString:str] forState:UIControlStateNormal];
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[self.nameLael setTitle:userModel.nickName forState:UIControlStateNormal];
|
|
|
|
}
|
|
-(void)tappushInfo{
|
|
|
|
InfoViewController*infovc=[[InfoViewController alloc]init];
|
|
[self.navigationController pushViewController:infovc animated:YES];
|
|
self.navigationController.navigationBarHidden=NO;
|
|
}
|
|
|
|
-(void)creatTableView{
|
|
AppDelegate*myDelegate=[[UIApplication sharedApplication]delegate];
|
|
|
|
// UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(10,160*myDelegate.autoSizeScaleY, kScreenSize.width - 60 - 10 , 50*6*myDelegate.autoSizeScaleY) style:UITableViewStylePlain];
|
|
UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(10,160*myDelegate.autoSizeScaleY, kScreenSize.width - 60 - 10 , kScreenSize.height - CGRectGetMaxY(self.nameLael.frame) - 10) style:UITableViewStylePlain];
|
|
self.tableView=tableView;
|
|
tableView.dataSource=self;
|
|
tableView.delegate=self;
|
|
tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
|
|
tableView.scrollEnabled=YES;
|
|
tableView.showsVerticalScrollIndicator=NO;
|
|
[self.view addSubview:tableView];
|
|
self.tableView.backgroundColor=COLOR_MIAN;
|
|
|
|
}
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
|
return 1;
|
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
return 7;
|
|
}
|
|
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
//static NSString *CellId=@"CellID";
|
|
leftCell*cell=[tableView dequeueReusableCellWithIdentifier:@"leftCell"];
|
|
if (cell==nil) {
|
|
cell= [[[NSBundle mainBundle]loadNibNamed:@"leftCell" owner:self options:nil]lastObject];
|
|
|
|
}
|
|
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
|
|
cell.textLabel.font=[UIFont systemFontOfSize:20.0f];
|
|
//cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"user_bg.png"]];
|
|
cell.backgroundColor=[UIColor clearColor];
|
|
cell.selectedBackgroundView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
LeftCellmodel*lModel=[[LeftCellmodel alloc]init];
|
|
lModel.headig=self.headimgeArr[indexPath.row];
|
|
lModel.funTitle=self.tileArr[indexPath.row];
|
|
[cell.headimag setImage:[UIImage imageNamed:lModel.headig]];
|
|
cell.titleLabel.text=lModel.funTitle;
|
|
return cell;
|
|
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{ AppDelegate*myDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
|
|
return 50*myDelegate.autoSizeScaleY;
|
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
if (indexPath.row==1) {
|
|
/**
|
|
测试
|
|
*/
|
|
// LeftViewController*left=[[LeftViewController alloc]init];
|
|
// // CenterViewController * center = [[CenterViewController alloc]init];
|
|
// TwoControlViewController*twoControl=[[TwoControlViewController alloc]init];
|
|
//
|
|
//
|
|
//
|
|
// _ics=[[ICSDrawerController alloc]initWithLeftViewController:left centerViewController:twoControl];
|
|
//
|
|
// [self.navigationController pushViewController:_ics animated:YES];
|
|
dispatch_async(dispatch_get_main_queue(),^{
|
|
[self.drawer closeLeft];
|
|
});
|
|
|
|
|
|
}else if (indexPath.row==3){
|
|
SetViewController *setVc=[[SetViewController alloc]init];
|
|
setVc.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
|
|
|
|
self.navigationController.navigationBarHidden=NO;
|
|
[self.navigationController pushViewController:setVc animated:YES];
|
|
}else if (indexPath.row==5){
|
|
SaySomethingViewController*sayVc=[[SaySomethingViewController alloc]init];
|
|
self.navigationController.navigationBarHidden=NO;
|
|
[self.navigationController pushViewController:sayVc animated:YES];
|
|
|
|
}else if (indexPath.row==4){
|
|
ScanViewController*scanVC=[[ScanViewController alloc]init];
|
|
|
|
UINavigationController * nVC = [[UINavigationController alloc]initWithRootViewController:scanVC];
|
|
[self presentViewController: nVC animated:YES completion:^{
|
|
|
|
}];
|
|
|
|
}else if (indexPath.row==2){
|
|
BookViewController*bookWebVC=[[BookViewController alloc]init];
|
|
self.navigationController.navigationBarHidden=NO;
|
|
[self.navigationController pushViewController:bookWebVC animated:YES];
|
|
|
|
}else if (indexPath.row==0){
|
|
|
|
|
|
}else if (indexPath.row==6){
|
|
|
|
NSURL *url=[NSURL URLWithString:@"taobao://item.taobao.com/item.htm?id=535991514644"];
|
|
|
|
if ([[UIApplication sharedApplication] canOpenURL:url]) {
|
|
|
|
[[UIApplication sharedApplication] openURL:url];
|
|
|
|
|
|
}else{
|
|
|
|
PushMasssageWebViewController*cameraShopVC=[[PushMasssageWebViewController alloc]init];
|
|
cameraShopVC.pushlink =IfishCameraTaoBaoShop;
|
|
cameraShopVC.pushtitle = @"购买摄像头";
|
|
self.navigationController.navigationBarHidden=NO;
|
|
[self.navigationController pushViewController:cameraShopVC animated:YES];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
self.navigationController.navigationBarHidden=YES;
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self UserImageView];
|
|
});
|
|
}
|
|
#pragma mark - ICSDrawerControllerPresenting
|
|
- (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController
|
|
{
|
|
self.view.userInteractionEnabled = NO;
|
|
}
|
|
|
|
- (void)drawerControllerDidOpen:(ICSDrawerController *)drawerController
|
|
{
|
|
self.view.userInteractionEnabled = YES;
|
|
}
|
|
|
|
- (void)drawerControllerWillClose:(ICSDrawerController *)drawerController
|
|
{
|
|
self.view.userInteractionEnabled = NO;
|
|
}
|
|
|
|
- (void)drawerControllerDidClose:(ICSDrawerController *)drawerController
|
|
{
|
|
self.view.userInteractionEnabled = YES;
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
- (BOOL)prefersStatusBarHidden
|
|
{
|
|
return NO;
|
|
}
|
|
//- (UIStatusBarStyle)preferredStatusBarStyle
|
|
//{
|
|
// return UIStatusBarStyleLightContent;
|
|
//}
|
|
// 暂时不便变状态栏
|
|
|
|
@end
|