123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //
- // MyViewController.m
- // ChinaTheoryNetwork
- //
- // Created by 张毅成 on 2019/1/21.
- // Copyright © 2019 张毅成. All rights reserved.
- //
- #import "MyViewController.h"
- #import "MyModel.h"
- #import "MyTableViewCell.h"
- #import "MyDetailViewController.h"
- #import "SettingViewController.h"
- #import "MyOrderViewController.h"
- #import "NoticeViewController.h"
- #import "LearninglistViewController.h"
- #import "MyClubApplicationViewController.h"
- #import "LoginViewController.h"
- #import "MyPaperViewController.h"
- @interface MyViewController ()<UITableViewDelegate, UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (strong, nonatomic) MyModel *model;
- @end
- @implementation MyViewController
- - (MyModel *)model {
- if (!_model) {
- _model = [MyModel new];
- }
- return _model;
- }
- - (void)Network {
- NSString *URL = @"my/info";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSLog(@"%@",responseObject);
- if ([responseObject[@"code"] integerValue] == 0) {
- self.model = [MyModel modelWithJSON:responseObject[@"data"][@"userInfo"]];
- USERDEFAULTSSET(self.model.nickname, @"nickname");
- USERDEFAULTSSET(self.model.isApprove, @"kisApprove");
- USERDEFAULTSSET(responseObject[@"data"][@"imageUrl"], @"headimgurl");
- [[NSUserDefaults standardUserDefaults] synchronize];
- [self.tableView reloadData];
- NSString *cacheKey = @"ZYCCacheMyModel";
- YYCache *cache = [YYCache cacheWithName:@"ZYCCache"];
- [cache setObject:self.model forKey:cacheKey];
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = kBackgroundColor;
- [self createTableView];
- [self setupLeftButton];
- [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithBgColor:kMainColor alpha:1.0] forBarMetrics:UIBarMetricsDefault];
- if (kIsLogin) {
- [self getCache];
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (kIsLogin) {
- [self Network];
- }else{
- [self.tableView reloadData];
- }
- }
- - (void)createTableView {
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.tableFooterView = [UIView new];
- self.tableView.rowHeight = UITableViewAutomaticDimension;
- self.tableView.estimatedRowHeight = 60;
- // self.tableView.separatorStyle = 0;
- self.tableView.backgroundColor = kBackgroundColor;
- }
- - (void)setupLeftButton {
- UIButton *LeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
- LeftButton.frame = CGRectMake(0, 0, 40, 40);
- [LeftButton setImage:[UIImage imageNamed:@"消息-1"] forState:(UIControlStateNormal)];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:LeftButton];
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFixedSpace) target:nil action:nil];
- item.width = -7;
- self.navigationItem.leftBarButtonItems = @[item,leftItem];
- [LeftButton addTarget:self action:@selector(didTouchLeftButton) forControlEvents:UIControlEventTouchUpInside];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 5;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section > 1) {
- return 10;
- }
- return 0.01;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- if (section == [tableView numberOfSections] - 1) {
- return 10;
- }
- return 0.01;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [UIView new];
- view.backgroundColor = kBackgroundColor;
- return view;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *view = [UIView new];
- view.backgroundColor = kBackgroundColor;
- return view;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- NSArray *array = self.model.arrayData[section];
- return array.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- MyTableViewCell *cell0 = [MyTableViewCell cellWithTableView:tableView AndIndex:0];
- MyTableViewCell *cell1 = [MyTableViewCell cellWithTableView:tableView AndIndex:1];
- //注册3D Touch
- /**
- 从iOS9开始,我们可以通过这个类来判断运行程序对应的设备是否支持3D Touch功能。
- UIForceTouchCapabilityUnknown = 0, //未知
- UIForceTouchCapabilityUnavailable = 1, //不可用
- UIForceTouchCapabilityAvailable = 2 //可用
- */
- if ([self respondsToSelector:@selector(traitCollection)]) {
- if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]) {
- if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
- [self registerForPreviewingWithDelegate:(id)self sourceView:cell0];
- [self registerForPreviewingWithDelegate:(id)self sourceView:cell1];
- }
- }
- }
-
- if (indexPath.section == 0) {
- cell0.imageViewIcon.layer.masksToBounds = true;
- cell0.imageViewIcon.layer.cornerRadius = 30;
- cell0.imageViewIcon.layer.borderColor = [UIColor hexStringToColor:@"abd1ef"].CGColor;
- cell0.imageViewIcon.layer.borderWidth = 2.0f;
- if (!kIsLogin) {
- cell0.labelTitle.text = @"点击登录";
- cell0.labelDetail.hidden = true;
- [cell0.imageViewIcon setImage:[UIImage imageNamed:@"imagePlaceholder"]];
- }else{
- cell0.labelDetail.hidden = false;
- cell0.labelTitle.text = self.model.nickname?:@"暂无";
- cell0.labelDetail.text = [NSString stringWithFormat:@"%@",self.model.myselfMsg?:@"暂无签名"];
- // [cell0.imageViewIcon sd_setImageWithURL:[NSURL URLWithString:kUserHeadImageURL] placeholderImage:[UIImage imageNamed:@"imagePlaceholder"]];
- cell0.blockDidTouchLabelDetail = ^{
- // MyAchievementViewController *controller = [MyAchievementViewController new];
- // controller.model = self.model;
- // [self.navigationController pushViewController:controller animated:true];
- };
- }
- return cell0;
- }else{
- [cell1 setDataWithModel:self.model.arrayData[indexPath.section][indexPath.row]];
- // if (kIsVip) {
- // if (indexPath.section == 1) {
- // if (indexPath.row == 2) {
- // cell1.labelDetail.text = @"";
- // }
- // }
- // }
- }
- return cell1;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- //判断是否登录
- kIsLoginToPush
- if (indexPath.section == 0) {
- MyDetailViewController *controller = [MyDetailViewController new];
- controller.model = self.model;
- [self.navigationController pushViewController:controller animated:true];
- }else if (indexPath.section == 1) {
- if (indexPath.row == 0) {//同行阅读
- LearninglistViewController *controller = [LearninglistViewController new];
- [self.navigationController pushViewController:controller animated:true];
- }else if (indexPath.row == 2) {//学习报告
-
- }
- // else if (indexPath.row == 2) {//我的投稿
- // MyClubApplicationViewController *controller = [MyClubApplicationViewController new];
- // [self.navigationController pushViewController:controller animated:true];
- // }
- }else if (indexPath.section == 2) {
- if (indexPath.row == 0) {//作者认证
-
- }else if (indexPath.row == 1) {//我的论文
- MyPaperViewController *controller = [MyPaperViewController new];
- [self.navigationController pushViewController:controller animated:true];
- }else if (indexPath.row == 2) {//账户
- // MyOrderViewController *controller = [MyOrderViewController new];
- // [self.navigationController pushViewController:controller animated:true];
- }
- }else if (indexPath.section == 3) {
- if (indexPath.row == 0) {//我的会员
-
- }else if (indexPath.row == 1) {//分享
- // CTNShareController *controller = [CTNShareController new];
- // [controller shareBasic];
- }
- }else if (indexPath.section == 4) {
- //设置
- SettingViewController *controller = [SettingViewController new];
- controller.modelMy = self.model;
- [self.navigationController pushViewController:controller animated:true];
- }
- }
- - (void)didTouchLeftButton {
- kIsLoginToPush
- NoticeViewController *controller = [NoticeViewController new];
- [self.navigationController pushViewController:controller animated:true];
- }
- - (void)getCache {
- NSString *cacheKey = @"ZYCCacheMyModel";
- YYCache *cache = [YYCache cacheWithName:@"ZYCCache"];
- BOOL isContains = [cache containsObjectForKey:cacheKey];
- NSLog(@"%d",isContains);
- id value = [cache objectForKey:cacheKey];
- NSLog(@"%@",value);
- if (value) {
- self.model = value;
- [self.tableView reloadData];
- }
- }
- @end
|