#import "todayadviceViewController.h"
#import "advicefirstCell.h"
#import "advertiseCell.h"
#import "adversecondcell.h"
#import "hotmessagecell.h"
#import "gusstableviewCell.h"
#import "hotmessageModel.h"
#import "commentModel.h"
#import "firstheaderView.h"
#import "adfirsttwoView.h"
#import "firstheaderView.h"
#import "thirdheaderview.h"
#import "todayideaModel.h"
#import "commentModel.h"
#import <MJExtension.h>
#import "NSString+Extension.h"
#import "jianbtn.h"
#import "firstfooterview.h"
#import "jianbanview.h"
#import "todayideaModel.h"
#import "detailModel.h"
@interface todayadviceViewController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,FloatViewDelegate,UITextFieldDelegate,UITableViewDelegate>
@property(nonatomic,strong)UITableView *onetableview;
@property(nonatomic,strong)NSMutableArray<todayideaModel *>*ideamodels;
@property(nonatomic,strong)NSMutableArray<commentModel *>*commentmodels;
@property(nonatomic,strong)jianbanview *banview;
@property(nonatomic,strong)todayideaModel *ideamodel;
@property(nonatomic,assign)NSInteger pageNum;
@property(nonatomic,assign)NSInteger likeNum;
@property(nonatomic,strong)commentModel *comModel;
@property(nonatomic,strong)detailModel *dModel;
@property(nonatomic,strong)NSMutableArray<detailModel *>*detailmodels;
@end
static dispatch_once_t disonce;
@implementation todayadviceViewController
-(NSMutableArray<detailModel*>*)detailmodels{
if (_detailmodels==nil) {
_detailmodels = [NSMutableArray array];
}
return _detailmodels;
}
-(NSMutableArray<todayideaModel*>*)ideamodels{
if (_ideamodels ==nil) {
_ideamodels = [NSMutableArray array];
}
return _ideamodels;
}
-(NSMutableArray<commentModel*>*)commentmodels{
if (_commentmodels ==nil) {
_commentmodels = [NSMutableArray array];
}
return _commentmodels;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBar.hidden = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
//去掉导航栏下边的线
self.navigationController.navigationBar.tintColor = [UIColor grayColor];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -36)
forBarMetrics:UIBarMetricsDefault];
self.navigationItem.title = @"专家在线"; self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor colorWithRed:51.0/255 green:51.0/255 blue:51.0/255 alpha:1]};
//去掉导航栏下边的线
self.navigationController.navigationBar.tintColor = [UIColor grayColor];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -36)
forBarMetrics:UIBarMetricsDefault];
//为导航栏添加右侧按钮
UIBarButtonItem *right1 = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"share"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(rightAction1)];
//为导航栏添加右侧按钮2
UIBarButtonItem *right2 = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"Collection-"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(rightAction2)];
NSArray *arr = [[NSArray alloc]initWithObjects:right1, right2, nil];
self.navigationItem.rightBarButtonItems = arr;
#pragma mark获取文章详情
CGRect bounds = [UIScreen mainScreen].bounds;
NSString *twostr =@"article_details";
NSString *urlstring = [NSString stringWithFormat:@"%@%@",BaseURL,twostr];
NSMutableDictionary *paramsone = [NSMutableDictionary dictionary];
NSString *uidstr = [[NSUserDefaults standardUserDefaults]objectForKey:@"uid"];
paramsone[@"id"] =_idstr;
paramsone[@"uid"]=uidstr;
[NSObject POST:urlstring parameters:paramsone progress:^(NSProgress *downloadProgress) {
} completionHandler:^(id responseObj, NSError *error) {
NSLog(@"获取文章详情:%@",responseObj);
if ([responseObj[@"state"]integerValue]==1) {
NSDictionary *dic = responseObj[@"data"];
_dModel = [detailModel mj_objectWithKeyValues:dic];
[self.onetableview reloadData];
}else{
[SVProgressHUD setMinimumDismissTimeInterval:1];
[SVProgressHUD showErrorWithStatus:responseObj[@"message"]];
}
}];
//ios中今日建议获取文章详情
_onetableview = [[UITableView alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_onetableview.delegate = self;
_onetableview.dataSource = self;
_onetableview.backgroundColor=[UIColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1];
[self.view addSubview:_onetableview];
self.floatView = [FloatView floatViewWithRadius:30 point:CGPointMake(bounds.size.width - 100 , bounds.size.height - 150) image:[UIImage imageNamed:@"组-13"] inView:nil];
//设置代理(代理方法调用在最下方)
self.floatView.delegate = self;
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bigMap)];
recognizer.delegate = self;
[self.floatView addGestureRecognizer:recognizer];
[self.view addSubview:self.floatView];
#pragma mark查看全部留言
self.onetableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[self updateData];
}];
NSString *uidstring = [[NSUserDefaults standardUserDefaults]objectForKey:@"uid"];
//获取文章评论
NSString *pinglun = @"get_comment";
NSString *pinglustring = [NSString stringWithFormat:@"%@%@",BaseURL,pinglun];
NSMutableDictionary *parmastwo = [NSMutableDictionary dictionary];
parmastwo[@"id"]=_idstr;
parmastwo[@"p"]=@1;
parmastwo[@"num"]=@4;
parmastwo[@"uid"]=uidstring;
[NSObject POST:pinglustring parameters:parmastwo progress:^(NSProgress *downloadProgress) {
} completionHandler:^(id responseObj, NSError *error) {
NSArray *array = responseObj[@"data"];
for (NSDictionary *dic in array) {
_articleidstr = dic[@"article_id"];
_idstringtwo = dic[@"id"];
[[NSUserDefaults standardUserDefaults]setObject:_articleidstr forKey:@"article_id"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
NSMutableArray *modelarray = [NSMutableArray array];
for (NSDictionary *dic in responseObj[@"data"]) {
todayideaModel *ideaModel = [todayideaModel mj_objectWithKeyValues:dic];
NSArray *insidearray = dic[@"next_comment"];
ideaModel.commentModelArray = [NSMutableArray array];
for (NSDictionary *dit in insidearray) {
commentModel *cmodel = [commentModel mj_objectWithKeyValues:dit];
[ideaModel.commentModelArray addObject:cmodel];
}
_commentmodels = ideaModel.commentModelArray;
[self.ideamodels addObject:ideaModel];
}
[self.onetableview reloadData];
}];
UIButton *footerBtn = [[UIButton alloc]init];
footerBtn.backgroundColor = [UIColor clearColor];
[footerBtn setTitle:@"查看更多评论>>" forState:UIControlStateNormal];
[footerBtn addTarget:self action:@selector(clickmore) forControlEvents:UIControlEventTouchUpInside];
[footerBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[_onetableview.tableFooterView addSubview:footerBtn];
}
-(void)clickmore{
NSLog(@"查看更多");
}
-(void)updateData{
[self.onetableview.mj_header endRefreshing];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1+self.ideamodels.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section==0) {
return 1;
}
return self.ideamodels[section-1].commentModelArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0&&indexPath.row==0) {
return 800;
}
commentviewCell *viewcell = [commentviewCell cellWithTableView:tableView];
return viewcell.commentlabel.frame.size.height;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0&&indexPath.row==0) {
UITableViewCell *viewcell = [UITableViewCell new];
//viewcell.backgroundColor = [UIColor redColor];
viewcell.backgroundColor = [UIColor yellowColor];
_yellowview = [[UIView alloc]init];
_yellowview.backgroundColor = [UIColor yellowColor];
[viewcell.contentView addSubview:_yellowview];
[_yellowview mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.right.mas_equalTo(0);
make.height.mas_equalTo(700);
}];
_webview = [[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[_yellowview addSubview:_webview];
[_webview sizeToFit];
NSString *str1 = _dModel.content;
str1 = [self htmlEntityDecode:str1];
[_webview loadHTMLString:str1 baseURL:[NSURL URLWithString:str1]];
[_webview.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
return viewcell;
}
commentviewCell *viewcell = [commentviewCell cellWithTableView:tableView];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
viewcell.separatorInset = UIEdgeInsetsMake(0, width, 0, 0);
todayideaModel *ideamodel = self.ideamodels[indexPath.section-1];
if (ideamodel.commentModelArray.count !=0) {
commentModel *cmodel = ideamodel.commentModelArray[indexPath.item];
NSString *str = nil;
if (![cmodel.reply_uid isEqualToString:@"0"]) {
str = [NSString stringWithFormat:@"%@回复%@:%@",cmodel.nickname,cmodel.nickname,cmodel.content];
NSLog(@"输出str的值-------:%@",str);
}else{
str = [NSString stringWithFormat:@"%@:%@",cmodel.nickname,cmodel.content];
}
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc] init];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
if ([text.string isMoreThanOneLineWithSize:CGSizeMake(width-40-20-20, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpaceing:5.0]) {
muStyle.lineSpacing = 5.0;//设置行间距离
}else{
muStyle.lineSpacing = CGFLOAT_MIN;//设置行间距离
}
[text addAttribute:NSParagraphStyleAttributeName value:muStyle range:NSMakeRange(0, text.length)];
[text addAttribute:NSForegroundColorAttributeName
value:[UIColor orangeColor]
range:NSMakeRange(0, cmodel.nickname.length)];
if (cmodel.rep_nickname.length>0) {
[text addAttribute:NSForegroundColorAttributeName
value:[UIColor orangeColor]
range:NSMakeRange(cmodel.rep_nickname.length + 2, cmodel.nickname.length)];
}
viewcell.commentlabel.attributedText = text;
}
return viewcell;
}
#pragma mark类似字符的转换
- (NSString *)htmlEntityDecode:(NSString *)string
{
string = [string stringByReplacingOccurrencesOfString:@""" withString:@"\""];
string = [string stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
string = [string stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
string = [string stringByReplacingOccurrencesOfString:@">" withString:@">"];
string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"]; // Do this last so
return string;
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if ([keyPath isEqualToString:@"contentSize"]) {
CGSize fittingSize = [_webview sizeThatFits:CGSizeZero];
_webview.frame = CGRectMake(0, 0, self.view.frame.size.width,700);
[_yellowview addSubview:_webview];
dispatch_once(&disonce, ^{
[self.onetableview reloadData];
});
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *view = [[UIView alloc]init];
return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc]init];
return view;
}
-(void)rightAction2{
NSLog(@"点击右侧按钮2");
}
-(void)rightAction1{
NSLog(@"点击右侧按钮");
}
#pragma mark点击浮动view
-(void)bigMap{
NSLog(@"点击浮动view");
}
@end