123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- //
- // AllCommentVC.m
- // jiaPei
- //
- // Created by apple on 15/11/23.
- // Copyright (c) 2015年 JCZ. All rights reserved.
- //
- #import "AllCommentVC.h"
- @interface AllCommentVC ()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate>
- {
- UIView* tfContainv;
- UITextView* tf;
- UIButton* postBtn;
-
- CGFloat tfcH;
- CGFloat tfcY;
- }
- @property(nonatomic,strong)NSArray* comments;
- @end
- @implementation AllCommentVC
- {
- UITableView* myTableView;
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
-
- [self getAllComments];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillShow:)
- name:UIKeyboardWillShowNotification
- object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillHide:)
- name:UIKeyboardWillHideNotification
- object:nil];
-
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- }
- #pragma mark -
- -(void)myInit
- {
- if (myDelegate.isNightMode) {
- [self.view setBackgroundColor:nightColor];
- }else{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- }
- [self configNavigationBar];
- [self setTitle:@"试题分析"];
-
- myTableView = [[UITableView alloc] initWithFrame:kFrame];
- myTableView.height -= 50 + kNavOffSet + kSafeAreaBottomHeight;
- [self.view addSubview:myTableView];
- [myTableView setBackgroundColor:[UIColor clearColor]];
- [myTableView setDataSource:self];
- [myTableView setDelegate:self];
- //UIScrollViewKeyboardDismissModeInteractive 这种是tableview拉到键盘的地方 键盘开始随手指移动 get起来
- myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
-
-
- tfcH = 50;
- CGFloat bd = 10;
- CGFloat btnw = 50;
-
- tfcY = kSize.height - tfcH - kNavOffSet - kSafeAreaBottomHeight;
-
- //NSLog(@"--%f----%f----%f---%f",tfcY,[[UIApplication sharedApplication] statusBarFrame].size.height,self.navigationController.navigationBar.frame.size.height,kSize.height);
-
- tfContainv = [[UIView alloc] initWithFrame:CGRectMake(0, tfcY, kSize.width, tfcH)];
- //灰色会效果更好点 似乎
- [tfContainv setBackgroundColor:[UIColor lightGrayColor]];
- [self.view addSubview:tfContainv];
-
- tf = [[UITextView alloc] initWithFrame:CGRectMake(bd, (tfcH - 25)/2, kSize.width-bd*3 - btnw, 25)];
- [tf setFont:[UIFont scaleSize:NormalFont]];
- [tf setFont:[UIFont scaleSize:15]];
- [tfContainv addSubview:tf];
- [tf setDelegate:self];
- // [tfContainv addSelfViewWithRect:CGRectMake(bd, tfcH - 1, kSize.width-bd*3 - btnw-4, 1) Color:defGreen];
-
-
- UIButton* btn =[[UIButton alloc] initWithFrame:CGRectMake(kSize.width - btnw - bd, (tfcH - 30)/2, btnw, 30)];
- [btn setTitle:@"发送" textColor:backGroundColor font:NormalFont fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(userEndEdit) forControlEvents:UIControlEventTouchUpInside];
- [btn setBackgroundColor:[UIColor grayColor]];
- [btn.layer setCornerRadius:5];
- [btn.layer setMasksToBounds:YES];
- postBtn = btn;
- [tfContainv addSubview: btn];
- }
- - (void)saveQuestionComment
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- //NSLog(@"com->%@,qid->%@",tf.text,_quest._id);
-
- NSMutableArray *arr=[NSMutableArray array];
-
- [arr property:_quest._id forKey:@"qId"];
- [arr property:tf.text forKey:@"desc"];
- if (myDelegate.isLogin) {
- NSString *str = defUser.userName;
- if (str && str.length!=0) {
- [arr property:defUser.userName forKey:@"name"];
- }else{
- [arr property:defUser.userDict[@"nickName"] forKey:@"name"];
- }
- [arr property:defUser.userDict[@"id"] forKey:@"userId"];
- [arr property:@"1" forKey:@"type"];
- }else{
- [arr property:@"驾考学员" forKey:@"name"];
- [arr property:@"2" forKey:@"type"];
- [arr property:@"" forKey:@"userId"];
- }
-
- NSString* method = @"saveQuestionComment";
-
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
-
- [MBProgressHUD hideHUDForView:self.view];
- //NSLog(@"同步请求返回的结果:%@",dict);
- if (dict && [dict[@"code"] isEqualToString:@"0"]) {
- ShowMsg(@"评论成功");
- tf.text = nil;
- [self getAllComments];
- }else{
- ShowMsg(dict[@"body"]);
- }
- }];
- }
- -(void)getAllComments
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- if ([defUser.car_type isEqualToString:@"2"]) {
- [arr property:_quest._id forKey:@"id"];
- } else {
- [arr property:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:_ydtQuestionModel.ID]] forKey:@"id"];
- }
-
- [arr property:@"" forKey:@"isPage"];
- [arr property:@"" forKey:@"pageSize"];
- [arr property:@"" forKey:@"currentPage"];
-
- NSString* method = @"getQuestionComments";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
- [MBProgressHUD hideHUDForView:self.view];
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ([dict[@"code"] isEqualToString:@"1"])
- {
- ShowMsg(dict[@"body"]);
- return;
- }
-
- _comments = dict[@"body"];
- if (![dict[@"body"] isKindOfClass:[NSArray class]]) {
- _comments = @[];
- }
-
- if (_comments.count < 1) {
- ShowMsg(@"暂无相关评论");
- }
-
- [myTableView reloadData];
- }];
- }
- #pragma mark -
- -(void)userEndEdit
- {
- if ([tf isFirstResponder]) {
- [tf resignFirstResponder];
- }
- [UIView animateWithDuration:.25 animations:^{
- tfContainv.frame = CGRectMake(0, tfcY, kSize.width, tfcH);
- }];
-
- NSCharacterSet *whitespace=[NSCharacterSet whitespaceAndNewlineCharacterSet];
- NSString* str=[tf.text stringByTrimmingCharactersInSet:whitespace];
- if (str.length < 1) {
- return;
- }
- [self saveQuestionComment];
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- // NSCharacterSet *whitespace=[NSCharacterSet whitespaceAndNewlineCharacterSet];
- // NSString* str=[tf.text stringByTrimmingCharactersInSet:whitespace];
-
- //这样来做应该会更准确
- NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text];
- [changedString replaceCharactersInRange:range withString:text];
-
- if (changedString.length < 1) {
- [postBtn setEnabled:NO];
- [postBtn setBackgroundColor:[UIColor grayColor]];
- }else{
- [postBtn setEnabled:YES];
- [postBtn setBackgroundColor:defGreen];
- }
-
- if ([text isEqualToString:@"\n"]){
- [self userEndEdit];
- return NO;
- //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
- }
- return YES;
- }
- - (void)keyboardWillShow:(NSNotification *)aNotification
- {
- NSDictionary *userInfo = [aNotification userInfo];
- NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
- CGRect keyboardRect = [aValue CGRectValue];
- CGFloat kbH = keyboardRect.size.height;
-
- [UIView animateWithDuration:.25 animations:^{
- tfContainv.frame = CGRectMake(0, tfcY - kbH + kSafeAreaBottomHeight, kSize.width, tfcH);
- }];
- }
- - (void)keyboardWillHide:(NSNotification *)aNotification
- {
- if ([tf isFirstResponder]) {
- [tf resignFirstResponder];
- }
- [UIView animateWithDuration:.25 animations:^{
- tfContainv.frame = CGRectMake(0, tfcY, kSize.width, tfcH);
- }];
- }
- #pragma mark -
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _comments.count ;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary *dic = _comments[indexPath.row];
- return 110 + [dic[@"QC_DESC"] heightForWid:(kSize.width - 80) Font:15];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CommentCell* cell = [CommentCell cellForTableView:tableView Style:CommentCellStyleQuestion];
- if(indexPath.row < _comments.count){
- [cell setCommentDic:_comments[indexPath.row]];
- }
- return cell;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
- return [UIView new];
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .1;
- }
- @end
|