//
|
// discoverGoodsDetailViewController.m
|
// BuWanVideo2.0
|
//
|
// Created by apple on 17/1/4.
|
// Copyright © 2017年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "discoverGoodsDetailViewController.h"
|
|
#import "findTitleTableViewCell.h"
|
#import "findcommentTableViewCell.h"
|
#import "XYRChildTableViewCell.h"
|
|
#import "allCommentsViewController.h"
|
#import "WEBViewController.h"
|
#import "LoggingViewController.h"
|
|
//#import <AlibcTradeSDK/AlibcTradeSDK.h>
|
//#import <AlibcTradeSDK/AlibcTradeService.h>
|
//#import <AlibcTradeSDK/AlibcTradePageFactory.h>
|
//#import <AlibcTradeSDK/AlibcTradeShowParams.h>
|
|
@interface discoverGoodsDetailViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIGestureRecognizerDelegate>{
|
UITableView *_tableView;
|
|
UIView *_replyMessageView; //回复的输入视图
|
UIButton *sendButton; //回复的按钮
|
UITextField *_textField; //回复的输入框
|
|
UITapGestureRecognizer *Tap;//当评论框出现的时候,要把这个手势添加到tableView,当评论框消失的时候,要移除手势,否者会出现“猜你喜欢”无法点击的情况,因为手势会拦截点击事件
|
BOOL _isCollection;
|
}
|
|
@property (nonatomic,strong) NSDictionary *ItemDetailMessage; //商品详情页信息
|
@property (nonatomic,strong) NSArray *commentMessage; //商品详情页评论
|
@property (nonatomic,strong) NSMutableArray *RecommendListData; //猜你喜欢
|
|
@end
|
|
@implementation discoverGoodsDetailViewController
|
|
- (void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
[self.navigationController setNavigationBarHidden:YES animated:YES];
|
}
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
[super viewWillDisappear:animated];
|
[self.navigationController setNavigationBarHidden:NO animated:YES];
|
}
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
//增加通知中心监听,当键盘出现或消失时收出消息
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
|
[self creatUI];
|
}
|
|
-(void)creatUI{
|
if (!_tableView) {
|
_tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, -22, KScreenW, KScreenH+22) style:UITableViewStyleGrouped];
|
_tableView.delegate=self;
|
_tableView.dataSource=self;
|
_tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
|
_tableView.backgroundColor = kGlobalBackgroundColor;
|
_tableView.showsVerticalScrollIndicator = NO;
|
|
//注册cell
|
[_tableView registerNib:[UINib nibWithNibName:@"findTitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"findTitleTableViewCellID"];
|
[_tableView registerNib:[UINib nibWithNibName:@"findcommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"findcommentTableViewCellID"];
|
[_tableView registerNib:[UINib nibWithNibName:@"XYRChildTableViewCell" bundle:nil] forCellReuseIdentifier:@"XYRChildTableViewCellID"];
|
[self.view addSubview:_tableView];
|
}
|
|
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenW)];
|
imageView.contentMode=UIViewContentModeScaleAspectFill;
|
imageView.userInteractionEnabled=YES;
|
|
[imageView setYthImageWithURL:_goodspic_url placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
_tableView.tableHeaderView=imageView;
|
|
UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 64)];
|
CAGradientLayer *gradientLayer= [CAGradientLayer layer]; //设置渐变效果
|
gradientLayer.bounds = headerView.bounds;
|
gradientLayer.borderWidth = 0;
|
gradientLayer.frame =CGRectMake(headerView.bounds.origin.x, headerView.bounds.origin.y, KScreenW, 64);
|
gradientLayer.colors = [NSArray arrayWithObjects:
|
(id)[kGlobalMainColor CGColor],
|
(id)[[UIColor clearColor] CGColor], nil];
|
gradientLayer.startPoint = CGPointMake(0.0, 0.0);
|
gradientLayer.endPoint = CGPointMake(0.0, 1.0);
|
[headerView.layer insertSublayer:gradientLayer atIndex:0];
|
[self.view addSubview:headerView];
|
|
//返回按钮
|
UIButton *backButton=[[UIButton alloc] initWithFrame:CGRectMake(2, 25, 70, 30)];
|
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
// [backButton setTitle:@"<返回" forState:UIControlStateNormal];
|
// [backButton.titleLabel setFont:[UIFont systemFontOfSize:18]];
|
[backButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
|
[backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
|
[headerView addSubview:backButton];
|
|
//加载详细数据
|
[self loadDetailData:@"疯狂加载中"];
|
|
//输入框视图
|
[self CommentBox];
|
}
|
|
-(void)loadDetailData:(NSString *)str{
|
[SVProgressHUD showWithStatus:str];
|
[[YTHNetInterface startInterface] getGoodsItemDetailWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
[SVProgressHUD dismiss];
|
NSDictionary *dataGoodsDetailList=[result objectForKey:@"Data"];
|
_ItemDetailMessage=[dataGoodsDetailList objectForKey:@"Item"];
|
_commentMessage=[[dataGoodsDetailList objectForKey:@"comment"] objectForKey:@"data"];
|
_isCollection=[[dataGoodsDetailList objectForKey:@"collect"] boolValue];
|
_RecommendListData=[_ItemDetailMessage objectForKey:@"RecommendList"];
|
[_tableView reloadData];
|
}else{
|
NSLog(@"%@",error);
|
[SVProgressHUD showErrorWithStatus:@"加载失败"];
|
}
|
}];
|
}
|
|
-(void)CommentBox{
|
//创建手势事件
|
Tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignResponder)];
|
Tap.delegate=self;
|
|
UIImageView *backimage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, KScreenW-80 , 30)];
|
backimage.image=[[UIImage imageNamed:@"输入框"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 40, 20, backimage.frame.size.width-40)];
|
|
//回复的输入视图
|
_replyMessageView=[[UIView alloc] initWithFrame:CGRectMake(0, _tableView.frame.size.height-50, KScreenW, 50)];
|
_replyMessageView.backgroundColor=[UIColor whiteColor];
|
|
//回复的输入框
|
_textField=[[UITextField alloc] initWithFrame:CGRectMake(20, 10, KScreenW-90, 30)];
|
_textField.delegate=self;
|
_textField.backgroundColor=kGlobalBackgroundColor;
|
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
_textField.placeholder=@" 我也来说两句...";
|
|
//回复发送按钮
|
sendButton=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-60, 10, 50, 30)];
|
[sendButton setBackgroundImage:[[UIImage imageNamed:@"发表"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
|
|
[sendButton setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
|
[sendButton setTitle:@"发送" forState:UIControlStateNormal];
|
[sendButton addTarget:self action:@selector(PostComment) forControlEvents:UIControlEventTouchUpInside];
|
|
[_replyMessageView addSubview:backimage];
|
[_replyMessageView addSubview:_textField];
|
[_replyMessageView addSubview:sendButton];
|
|
[self.view addSubview:_replyMessageView];
|
[_replyMessageView setHidden:YES];
|
}
|
|
-(void)resignResponder{
|
[self HideBox];
|
}
|
|
-(void)PostComment{
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
|
[self HideBox];
|
//已登录
|
[[YTHNetInterface startInterface] addCommentWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withContent:_textField.text withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
[SVProgressHUD showSuccessWithStatus:@"评论成功"];
|
[self HideBox];
|
[self loadDetailData:@"刷新中..."];
|
_textField.text=@"";
|
}else{
|
[SVProgressHUD dismiss];
|
}
|
}];
|
}else{
|
//未登录,引导用户登录
|
LoggingViewController *loginVC=[[LoggingViewController alloc] init];
|
loginVC.ispresent=YES;
|
[self presentViewController:loginVC animated:YES completion:^{
|
|
}];
|
}
|
}
|
|
/**
|
显示评论框
|
*/
|
-(void)displayBox{
|
[_replyMessageView setHidden:NO];
|
[_textField becomeFirstResponder];
|
[_tableView addGestureRecognizer:Tap];
|
}
|
|
/**
|
隐藏评论框
|
*/
|
-(void)HideBox{
|
[_textField resignFirstResponder];
|
[_replyMessageView setHidden:YES];
|
[_tableView removeGestureRecognizer:Tap];
|
}
|
|
/**
|
返回
|
*/
|
-(void)back{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
/**
|
添加评论
|
|
@param sender 添加评论的按钮
|
*/
|
-(void)addCommits:(UIButton *)sender{
|
NSLog(@"添加评论");
|
[self displayBox];
|
}
|
|
/**
|
查看全部评论
|
|
@param sender 查看全部评论的按钮
|
*/
|
-(void)lookAllCommit:(UIButton *)sender{
|
NSLog(@"查看全部评论");
|
allCommentsViewController *allCommentsVC=[[allCommentsViewController alloc] init];
|
allCommentsVC.goodsId=_goodsId;
|
[self.navigationController pushViewController:allCommentsVC animated:YES];
|
}
|
|
-(void)gotoBuyGoods:(UIButton *)sender{
|
NSString *goodsStr=[[_ItemDetailMessage objectForKey:@"Item"] objectForKey:@"Click_url"];
|
[self openURL:goodsStr];
|
}
|
|
-(void)openURL:(NSString *)URL{
|
// 判断当前系统是否有安装淘宝客户端
|
if ([URL rangeOfString:@"taobao"].location !=NSNotFound) {
|
//淘宝客户端
|
NSString *agreement = [URL substringToIndex:5];
|
NSString *httpsUrl = [URL stringByReplacingOccurrencesOfString:@"https" withString:@"tbopen"];
|
NSString *httpUrl = [URL stringByReplacingOccurrencesOfString:@"http" withString:@"tbopen"];
|
NSString *taobaoUrl = [agreement isEqualToString:@"https"]?httpsUrl:httpUrl;
|
NSURL *url = [NSURL URLWithString:taobaoUrl];
|
if ([[UIApplication sharedApplication] canOpenURL:url]) {
|
// 如果已经安装淘宝客户端,就使用客户端打开链接
|
[[UIApplication sharedApplication] openURL:url];
|
}else{
|
[self openUrlWithBrowser:URL];
|
}
|
}else if([URL rangeOfString:@"tmall"].location !=NSNotFound){//天猫客户端
|
NSString *agreement = [URL substringToIndex:5];
|
NSString *httpsUrl = [URL stringByReplacingOccurrencesOfString:@"https" withString:@"tmall"];
|
NSString *httpUrl = [URL stringByReplacingOccurrencesOfString:@"http" withString:@"tmall"];
|
NSString *taobaoUrl = [agreement isEqualToString:@"https"]?httpsUrl:httpUrl;
|
NSURL *url = [NSURL URLWithString:taobaoUrl];
|
if ([[UIApplication sharedApplication] canOpenURL:url]) {
|
// 如果已经安装天猫客户端,就使用客户端打开链接
|
[[UIApplication sharedApplication] openURL:url];
|
}else{
|
[self openUrlWithBrowser:URL];
|
}
|
}else{
|
//内置浏览器
|
[self openUrlWithBrowser:URL];
|
}
|
}
|
|
/**
|
内置网页视图打开网页
|
|
@param url 网页地址
|
*/
|
-(void)openUrlWithBrowser:(NSString *)url{
|
// 不能记住密码的方法
|
|
// WEBViewController *webVC=[[WEBViewController alloc] init];
|
// webVC.url=url;
|
// webVC.orMake=UIInterfaceOrientationMaskPortrait;
|
// [self presentViewController:webVC animated:YES completion:^{
|
//
|
// }];
|
|
// 可以记住淘宝密码的方法
|
// id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
|
// id<AlibcTradeService> service = [AlibcTradeSDK sharedInstance].tradeService;
|
// AlibcTradeShowParams *showParams = [[AlibcTradeShowParams alloc] init];
|
//
|
// [service show:self.navigationController page:page showParams:showParams taoKeParams:nil trackParam:[self trackParams] tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
|
//
|
// } tradeProcessFailedCallback:^(NSError * _Nullable error) {
|
//
|
// }];
|
}
|
|
- (NSDictionary *)trackParams {
|
return @{@"23594297": @"5de7c85d114a8ec635583a7c99200c9"};
|
}
|
|
/**
|
点击收藏按钮
|
|
@param sender 按钮
|
*/
|
-(void)clickCollectionBtn:(UIButton *)sender{
|
if([sender isSelected]){
|
sender.selected=NO;
|
[[YTHNetInterface startInterface] cancelCollectWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
if ([result objectForKey:@"IsPost"]) {
|
sender.selected=NO;
|
}else{
|
sender.selected=YES;
|
}
|
}else{
|
sender.selected=YES;
|
}
|
}];
|
}else{
|
sender.selected=YES;
|
[[YTHNetInterface startInterface] addCollectWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
if ([result objectForKey:@"IsPost"]) {
|
sender.selected=YES;
|
}else{
|
sender.selected=NO;
|
}
|
}else{
|
sender.selected=NO;
|
}
|
}];
|
}
|
}
|
|
#pragma mark -UITableViewDataSource
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
if ([_RecommendListData count]>0) {
|
return 3;
|
}else{
|
return 2;
|
}
|
}
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
if (section==0) {
|
return 1;
|
}else if(section==1){
|
return _commentMessage.count;
|
}else if(section==2){
|
return 1;
|
}
|
return 0;
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
if (indexPath.section==0) {
|
findTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"findTitleTableViewCellID" forIndexPath:indexPath];
|
NSDictionary *goodsItem=[_ItemDetailMessage objectForKey:@"Item"];
|
cell.goodsName.text=[goodsItem objectForKey:@"Title"];
|
cell.goodsPrice.text=[NSString stringWithFormat:@"¥%@",[goodsItem objectForKey:@"Zk_final_price"]];
|
|
NSDictionary *UserMessage=[_ItemDetailMessage objectForKey:@"LoginUser"];
|
[cell.userIcon setYthImageWithURL:[NSString stringWithFormat:@"%@%@",iconImageUrl,[UserMessage objectForKey:@"Portrait"]] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
cell.userName.text=[UserMessage objectForKey:@"Nickname"];
|
CGSize NameSize = [cell.userName.text boundingRectWithSize:CGSizeMake(KScreenW, 21) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
|
//设置用户名的宽度
|
if (NameSize.width>=KScreenW-130) {
|
cell.userNameLength.constant=KScreenW-130;
|
}else{
|
cell.userNameLength.constant=NameSize.width+8;
|
}
|
|
if (_isCollection) {
|
[cell.collectionBtn setSelected:YES];
|
}
|
int num=[[_ItemDetailMessage objectForKey:@"Collectcount"] intValue];
|
if (_isCollection) {
|
--num;
|
}
|
[cell.collectionBtn setTitle:[NSString stringWithFormat:@"收藏 %d ",num]forState:UIControlStateNormal];
|
[cell.collectionBtn setTitle:[NSString stringWithFormat:@"收藏 %d ",num+1] forState:UIControlStateSelected];
|
[cell.collectionBtn addTarget:self action:@selector(clickCollectionBtn:) forControlEvents:UIControlEventTouchUpInside];
|
|
[cell.toBuy addTarget:self action:@selector(gotoBuyGoods:) forControlEvents:UIControlEventTouchUpInside];
|
|
return cell;
|
}else if(indexPath.section==1){
|
findcommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"findcommentTableViewCellID" forIndexPath:indexPath];
|
NSDictionary *commentDic=[_commentMessage[indexPath.row] objectForKey:@"User"];
|
NSString *tempIconStr=[commentDic objectForKey:@"Portrait"];//保存头像地址
|
//判断头像地址是否为完整的地址
|
if (tempIconStr.length>5) {
|
if (![[tempIconStr substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {//不是完整的http地址
|
tempIconStr=[NSString stringWithFormat:@"%@%@",iconImageUrl,[commentDic objectForKey:@"Portrait"]];
|
}
|
[cell.userIconImage setYthImageWithURL:tempIconStr placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
|
}else{
|
[cell.userIconImage setImage:[UIImage imageNamed:@"关注默认头像"]];
|
}
|
|
cell.userName.text=[commentDic objectForKey:@"Nickname"];
|
cell.userTime.text=[[YTHNetInterface startInterface] getDate:[_commentMessage[indexPath.row] objectForKey:@"Createtime"]];
|
cell.userContent.text=[_commentMessage[indexPath.row] objectForKey:@"Content"];
|
return cell;
|
}else{
|
XYRChildTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XYRChildTableViewCellID" forIndexPath:indexPath];
|
cell.cellDatas=_RecommendListData;
|
cell.tableViewindex=indexPath;
|
cell.clickIndexpath = ^(NSIndexPath *index){
|
//点击猜你喜欢的商品,直接跳转淘宝或者天猫,再或者是网页,不用再出现现在的页面
|
NSString *goodsStr=[_RecommendListData[index.row] objectForKey:@"Click_url"];
|
[self openURL:goodsStr];
|
};
|
return cell;
|
}
|
}
|
|
#pragma mark -UITableViewDelegate
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
if (indexPath.section==0) {
|
return 195;
|
}else if(indexPath.section==1){
|
NSString *str=[_commentMessage[indexPath.row] objectForKey:@"Content"];
|
CGSize commentSize = [str boundingRectWithSize:CGSizeMake(KScreenW-44, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
|
return commentSize.height+65;
|
}else if(indexPath.section ==2){
|
if ([_RecommendListData count]%2==1) {
|
return ((KScreenW-30)/2+50)*([_RecommendListData count]/2+1);
|
}else{
|
return ((KScreenW-30)/2+50)*[_RecommendListData count]/2;
|
}
|
}
|
return 0;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
if(section==1){
|
return 36;
|
}else if(section==2){
|
return 60;
|
}
|
return 0;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
if (section==1) {
|
return 40;
|
}
|
return 0;
|
}
|
|
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
if(section==1){
|
UIView *HeaderView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 36)];
|
HeaderView.backgroundColor=kGlobalBackgroundColor;
|
//容器视图
|
UIView *contentView=[[UIView alloc] initWithFrame:CGRectMake(10, 0, KScreenW-20, 36)];
|
contentView.backgroundColor=[UIColor whiteColor];
|
[HeaderView addSubview:contentView];
|
//评论
|
UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(8, 0, 40, 36)];
|
titleLabel.font=[UIFont systemFontOfSize:15];
|
titleLabel.text=@"评论";
|
[contentView addSubview:titleLabel];
|
//评论数量
|
UILabel *numLabel=[[UILabel alloc] initWithFrame:CGRectMake(48, 0, 30, 36)];
|
numLabel.font=[UIFont systemFontOfSize:15];
|
numLabel.text=[NSString stringWithFormat:@"%d",(int)_commentMessage.count];
|
numLabel.textColor=YTHColor(155, 125, 98);
|
[contentView addSubview:numLabel];
|
//查看全部
|
UIButton * viewAll=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-88-20, 0, 80, 36)];
|
[viewAll setTitle:@"查看全部" forState:UIControlStateNormal];
|
[viewAll setTitleColor:YTHColor(155, 125, 98) forState:UIControlStateNormal];
|
[viewAll addTarget:self action:@selector(lookAllCommit:) forControlEvents:UIControlEventTouchUpInside];
|
viewAll.titleLabel.font=[UIFont systemFontOfSize:15.0];
|
[contentView addSubview:viewAll];
|
//分割线
|
UILabel *dividingLine=[[UILabel alloc] initWithFrame:CGRectMake(0, 35.5, KScreenW-36, 0.5)];
|
dividingLine.backgroundColor=kGlobalBackgroundColor;
|
[contentView addSubview:dividingLine];
|
|
return HeaderView;
|
}else if(section==2){
|
UIView *HeaderView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 50)];
|
HeaderView.backgroundColor=kGlobalBackgroundColor;
|
|
//图片
|
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 30, 30)];
|
imageView.image=[UIImage imageNamed:@"商品猜你喜欢"];
|
[HeaderView addSubview:imageView];
|
|
//标题
|
UILabel *titlelabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 10, 85, 30)];
|
titlelabel.text=@"猜你喜欢";
|
titlelabel.font=[UIFont systemFontOfSize:15];
|
[HeaderView addSubview:titlelabel];
|
return HeaderView;
|
}else{
|
return nil;
|
}
|
}
|
|
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
if (section==1) {
|
UIView *View=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 40)];
|
View.backgroundColor=kGlobalBackgroundColor;
|
|
UIButton *addCommit=[[UIButton alloc] initWithFrame:CGRectMake(10, 0, KScreenW-20, 40)];
|
[addCommit setTitle:@"添加评论" forState:UIControlStateNormal];
|
[addCommit setTitleColor:YTHColor(183, 183, 183) forState:UIControlStateNormal];
|
[addCommit addTarget:self action:@selector(addCommits:) forControlEvents:UIControlEventTouchUpInside];
|
addCommit.backgroundColor=[UIColor whiteColor];
|
addCommit.titleLabel.font=[UIFont systemFontOfSize:15.0];
|
|
[View addSubview:addCommit];
|
return View;
|
}else{
|
return nil;
|
}
|
}
|
|
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
|
return NO;
|
}
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
}
|
|
#pragma mark -UITextFieldDelegate
|
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
|
[_tableView setScrollEnabled:NO];
|
return YES;
|
}
|
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
|
[self.view endEditing:YES];
|
[self PostComment];
|
return YES;
|
}
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField{
|
[_tableView setScrollEnabled:YES];
|
_textField.placeholder=@"我也来说两句...";
|
}
|
|
#pragma mark 键盘隐藏
|
-(void)keyboardWillHide:(NSNotification *)notification{
|
_replyMessageView.frame=CGRectMake(0, _tableView.frame.size.height-50, self.view.frame.size.width, 50);
|
}
|
#pragma mark 键盘出现
|
-(void)keyboardWasShown:(NSNotification *)notification{
|
NSDictionary* info = [notification userInfo];
|
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到键盘的高度
|
_replyMessageView.frame=CGRectMake(0, _tableView.frame.size.height-72-kbSize.height, self.view.frame.size.width, 50);
|
}
|
|
@end
|