123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960 |
- //
- #import "TopicVC.h"
- #import "CommunityCell.h"
- #import "TopicComCell.h"
- #import "STButton.h"
- #import "LoginViewController.h"
- @interface TopicVC () <UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,UIActionSheetDelegate,TopicComCellDelegate,CommunityCellDelegate>
- {
- /**输入框的父视图
- */
- UIView* tfContainv;
- UITextView* tf;
- /**“发送”按钮
- */
- UIButton* postBtn;
-
- UITableView* myTableView;
-
- /**仅仅是某话题的详情
- */
- NSDictionary* model;
-
- /**某话题的评论列表列表
- */
- NSArray* models;
-
- /**全屏的阴影按钮
- */
- UIView *shadowView;
- /**下方的点赞按钮。保存引用,以便于修改
- */
- STButton* favBtn;
- /**收藏按钮。不是点赞
- */
- STButton* storeBtn;
- /**下方的评论按钮。保存引用,以便于修改
- */
- STButton* comBtn;
-
- /**显示有多少条评论,以及评论人数。
- */
- UIView* footer;
- UILabel* lblNames,*lblComCnt;
-
- /**当用户点击cell的评论按钮时,传来一个用户ID。需要保存在这里。
- */
- NSString* replayUser;
-
- //判断是否是话题拥有者
- BOOL isUser;
-
- //输入框内容
- NSString *commentString;
- }
- @end
- @implementation TopicVC
- -(void)dealloc{
-
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- }
- /**考虑到这个VC的表结构的问题。先去设置导航右按钮
- */
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self myInit];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- -(void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- [self getTopicInfo];
-
- if (_textViewActive) {
- _textViewActive = NO;
- [tf becomeFirstResponder];
- }
- }
- #pragma mark -
- -(void)myInit
- {
- [self setTitle:@"话题详情"];
- [self.view setBackgroundColor:[UIColor whiteColor]];
-
- if (_isNotification == NO)
- {
- //正常状态
- [self configNavigationBar];
- }
- else
- {
- //推送状态 要将根视图变回去
- UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
- [backBtn setTintColor:defGreen];
- self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBtn];
- }
-
- /**配置导航右按钮
- */
- UIBarButtonItem *backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"community3.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnClick:)];
- [backBbi setTintColor:defGreen];
- [backBbi setTag:2];
- [self.navigationItem setRightBarButtonItem:backBbi];
-
- CGFloat x,y,w,h,bd;
- NSInteger tag = 0;
-
- //配置bottombar
- CGFloat barH = 65;
- x = 0;
- y = 0;
- w = kSize.width;
- h = kSize.height - kNavOffSet - kSafeAreaBottomHeight - barH;
- UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped];
- tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, .1)];
- [self.view addSubview:tv];
- [tv setBackgroundColor:[UIColor whiteColor]];
- tv.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
- myTableView = tv;
- [myTableView setDelegate:self];
- [myTableView setDataSource:self];
- myTableView.estimatedSectionHeaderHeight = 0;
- [tv setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
-
- if ([tv respondsToSelector:@selector(setSeparatorInset:)])
- {
- [tv setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([tv respondsToSelector:@selector(setLayoutMargins:)])
- {
- [tv setLayoutMargins:UIEdgeInsetsZero];
- }
-
- y+=h;
- h = barH;
-
- tfContainv = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, h)];
- //NSLog(@"%@",NSStringFromCGRect(tfContainv.frame));
- [tfContainv setBackgroundColor:backGroundColor];
- [self.view addSubview:tfContainv];
-
-
- UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, h)];
- [vi setBackgroundColor:backGroundColor];
- [self.view addSubview:vi];
- // vi.hidden= YES;
-
- w = 50;
- bd = 10;
- tf = [[UITextView alloc] initWithFrame:CGRectMake(bd, (50 - 25)/2, kSize.width-bd*3 - w, 25)];
- [tf setFont:[UIFont scaleSize:NormalFont]];
- [tf setFont:[UIFont scaleSize:15]];
- [tfContainv addSubview:tf];
- [tf setDelegate:self];
-
- // [tfContainv addSelfViewWithRect:CGRectMake(bd, 25/2+25+1, kSize.width-bd*3 - w-4, 1) Color:defGreen];
-
- //注册通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-
-
- UIButton* btn =[[UIButton alloc] initWithFrame:CGRectMake(kSize.width - w - bd, (50 - 30)/2, w, 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];
-
- w = h*1.3;
- bd = (kSize.width - w*2)/5.0;
- x = bd*2;
- STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, 0, w, h)];
- [stBtn setStyle:1];
- [stBtn setImage:[UIImage imageNamed:@"community0.png"] withTitle:@"" Font:SmallFont forState:UIControlStateNormal];
- [stBtn setImage:[UIImage imageNamed:@"community1.png"] forState:UIControlStateSelected];
- [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [vi addSubview:stBtn];
- favBtn = stBtn;
- [stBtn setTag:tag++];//0
-
-
- x +=bd+w;
- stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, 0, w, h)];
- [stBtn setStyle:1];
- [stBtn setImage:[UIImage imageNamed:@"community2.png"] withTitle:@"评论" Font:SmallFont forState:UIControlStateNormal];
- [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [vi addSubview:stBtn];
- comBtn = stBtn;
- [stBtn setTag:1];
-
-
- /**tableView创建
- */
- vi = [[UIView alloc] init];
- [vi setBackgroundColor:[UIColor whiteColor]];
- footer = vi;
- UILabel* label;
- label = [[UILabel alloc] init];
- [vi addSubview:label];
- [label setTextColor:defGreen];
- [label setFont:[UIFont scaleSize:13]];
- label.numberOfLines = 0;
- lblNames = label;
- label = [[UILabel alloc] init];
- [vi addSubview:label];
- lblComCnt = label;
- [label setTextColor:contentTextColor];
- [label setFont:[UIFont scaleSize:13]];
- }
- -(void)dismissNavgation
- {
- //推送过来 返回主页面
- [myDelegate gotoLoad];
- }
- -(void)btnClick:(UIButton*)sender
- {
- NSInteger tag = sender.tag;
-
- if (0 == tag ||5 == tag ||6 == tag) {
- if (!myDelegate.isLogin) {
- [LoginViewController loginFromVC:self];
- return;
- }
- }
-
- if (0 == tag) {
- //话题点赞
- int num = [model[@"POINTNUM"] intValue] - [model[@"ISPOINT"] intValue];
- if (sender.selected) {
- [sender setTitle:[NSString stringWithFormat:@"赞(%d)",num] forState:UIControlStateNormal];
- [self deleteTopicCommentPoints];
- }else{
- [sender setTitle:[NSString stringWithFormat:@"赞(%d)",num+1] forState:UIControlStateNormal];
- [self uploadTopicCommentPoints];
- }
- sender.selected = !sender.selected;
- }
- if (1 == tag) {
- if (!myDelegate.isLogin) {
- LoginViewController* vc = [[LoginViewController alloc] init];
- vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:vc animated:YES completion:nil];
- }else{
- //展示输入框。
- [tf becomeFirstResponder];
- }
- }
-
- if ( 2 == tag) {
- [tf resignFirstResponder];
-
- if (shadowView) {
- //慢慢消失
- [self hideMenu];
- }else{
- //慢慢出现
-
- shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, -80, kSize.width, kSize.height)];
- shadowView.backgroundColor = [UIColor colorWithWhite:.1 alpha:0.42];
- [self.view addSubview:shadowView];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideMenu)];
- [shadowView addGestureRecognizer:tap];
-
-
- NSArray* titles;
- NSArray* images;
-
- if(isUser) {
- titles= @[@"删除",@"收藏"];
- images = @[@"community6.png",@"Topic_img03.png"];
- }else{
- titles= @[@"举报",@"收藏",@"屏蔽此人",@"屏蔽此条"];
- images = @[@"Topic_img02.png",@"Topic_img03.png",@"Topic_img02.png",@"Topic_img02.png"];
- }
- CGFloat w = kSize.width / titles.count;
- for (int i = 0; i<titles.count; i++) {
- STButton *stBtn = [[STButton alloc] initWithFrame:CGRectMake( w*i, 0, w, 80)];
- [stBtn setImage:[UIImage imageNamed:images[i]] withTitle:titles[i] Font:13 forState:UIControlStateNormal];
- [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [stBtn setBackgroundColor:[UIColor whiteColor]];
- [stBtn setTag:i + 5];
- [shadowView addSubview:stBtn];
-
- if (1 == i) {
-
- [stBtn setImage:[[UIImage imageNamed:images[1]] tint:defGreen] withTitle:@"取消收藏" Font:13 forState:UIControlStateSelected];
- [stBtn setTitleColor:defGreen forState:UIControlStateSelected];
- storeBtn = stBtn;
-
- if ([model[@"ISFAV"] integerValue] != 0)
- {
- storeBtn.selected = YES;
- }else{
- storeBtn.selected = NO;
- }
- }
- }
- // [shadowView addSelfViewWithRect:CGRectMake( w, 0, 1, 80) Color:KlineColor];
-
- [UIView animateWithDuration:.5 animations:^{
- shadowView.alpha = 1;
- shadowView.frame = kFrame;
- }];
- }
- }
- if ( 3 == tag) {
- //不用做隐藏操作
- //[self hideMenu];
- }
- if (5 == tag) {
- [self hideMenu];
- if (!isUser) {
- //举报
- UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"请选择举报类型" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"敏感话题",@"淫秽色情",@"垃圾广告",@"人身攻击", nil];
- [sheet setDelegate:self];
- [sheet showInView:self.view];
- }else{
-
- [self deleteTopicInfo];
- }
- }
- if (6 == tag) {
- //收藏
- [self hideMenu];
-
- if (sender.selected) {
- //取消
- [self deleteMyTopicFav];
-
- }else{
- //添加
- [self uploadTopicFav];
- }
- sender.selected = !sender.selected;
- }
- if (7 == tag) {
- NSMutableArray *arr = [NSMutableArray arrayWithArray:RQ_SHARE_FUNCTION.shieldPeopleIDArr];
- if (![arr containsObject:_userId]) {
- [arr addObject:_userId];
- RQ_SHARE_FUNCTION.shieldPeopleIDArr = arr.copy;
- }
- [self hideMenuAndPop];
- }
- if (tag == 8) {
- NSMutableArray *arr = [NSMutableArray arrayWithArray:RQ_SHARE_FUNCTION.shieldTopicIDArr];
- if (![arr containsObject:_topicId]) {
- [arr addObject:_topicId];
- RQ_SHARE_FUNCTION.shieldTopicIDArr = arr.copy;
- }
- [self hideMenuAndPop];
- }
- if (9 <= tag && tag <= 12) {
- [self hideMenu];
- ShowMsgUnOpen();
- }
- }
- -(void)hideMenu
- {
- [UIView animateWithDuration:.5 animations:^{
- shadowView.alpha = 0;
- shadowView.frame = CGRectMake(0, -80, kSize.width, kSize.height);
- } completion:^(BOOL finished) {
- [shadowView removeFromSuperview];
- shadowView = nil;
- }];
- }
- -(void)hideMenuAndPop
- {
- [UIView animateWithDuration:.5 animations:^{
- shadowView.alpha = 0;
- shadowView.frame = CGRectMake(0, -80, kSize.width, kSize.height);
- } completion:^(BOOL finished) {
- [shadowView removeFromSuperview];
- shadowView = nil;
- [self.navigationController popViewControllerAnimated:YES];
- }];
- }
- #pragma mark -
- /**获取话题详情
- */
- -(void)getTopicInfo
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"id" Value:_topicId];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"getTopicInfo";
- [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:@"0"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
-
- if (![dict isKindOfClass:[NSDictionary class]]) {
- ShowMsg(@"数据异常");
- return;
- }
-
- //这里要加个判断 防止从话题进入学车日记 对该条话题进行删除操作 在返回的时候自动查询返回为空导致crash
- if ([dict[@"body"] isKindOfClass:[NSDictionary class]]) {
- if ([dict[@"body"] allKeys].count != 0) {
- model = (NSDictionary *)dict[@"body"];
- _userId = model[@"CRUSER"];
- }
- }
-
-
- [myTableView reloadData];
-
- [self getTopicPoints];
-
- //判断是否是本人
- if ([defUser.userDict[@"id"] isEqualToString:model[@"CRUSER"]]) {
- isUser = YES;
- }else{
- isUser = NO;
- }
- //判断是否已点过赞
- NSString* str = [NSString stringWithFormat:@"赞(%@)",model[@"POINTNUM"]];
- [favBtn setTitle:str forState:UIControlStateNormal];
-
- if ([model[@"ISPOINT"] integerValue]) {
- [favBtn setSelected:YES];
- }else{
- [favBtn setSelected:NO];
- }
- }];
- }
- -(void)getTopicComments
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (!_topicId) {
- _topicId = @"1";
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"topicId" Value:_topicId];
- [arr addPro:@"isPage" Value:@""];
- [arr addPro:@"pageSize" Value:@""];
- [arr addPro:@"currentPage" Value:@""];
-
- NSString* method = @"getTopicComments";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
-
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
- models = dict[@"body"];
-
- //NSLog(@"返回评论列表------>%@",models);
-
- [lblComCnt setText:[NSString stringWithFormat:@"%d条评论",(int)models.count]];
- lblComCnt.frame = CGRectMake(10, lblNames.bottom, kSize.width, 30);
- [lblComCnt addViewWithRect:CGRectMake(10, lblNames.bottom, kSize.width-20, 1)];
- [comBtn setTitle:[NSString stringWithFormat:@"评论(%d)",(int)models.count] forState:UIControlStateNormal];
- footer.frame = CGRectMake(0, 0, kSize.width, lblComCnt.bottom);
-
- //要先改footer再刷新表 要不然 返回的区尾尺寸不对
- [myTableView reloadData];
- }];
-
- }
- /**获取点赞用户列表
- */
- -(void)getTopicPoints
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"topicId" Value:_topicId];
-
- NSString* method = @"getTopicPoints";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
-
- if (!dict) {
- ShowMsg(@"获取点赞列表失败!");
- lblNames.frame = CGRectMake(10, 0, kSize.width - 60, 30);
- [self getTopicComments];
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- lblNames.frame = CGRectMake(10, 0, kSize.width - 60, 30);
- [self getTopicComments];
- return;
- }
-
- NSArray *array = dict[@"body"];
- //NSLog(@"获取话题赞数---->%@",array);
-
- NSMutableString* str = [NSMutableString string];
- for (int i =0;i < array.count;i++) {
- if ( i < array.count - 1) {
- [str appendFormat:@"%@,",[array[i] objectForKey:@"NICKNAME"]];
- }else{
- [str appendFormat:@"%@ 等%d人赞过",[array[i] objectForKey:@"NICKNAME"],(int)array.count];
- }
- }
- if (array.count < 1) {
- [lblNames setText:@"还没人赞过呢"];
- }else{
- [lblNames setText:str];
- }
- //为了更好看。高度30是随意设置的。真正的高度是在下面一行计算的。
- lblNames.frame = CGRectMake(10, 0, kSize.width - 60, 30);
- lblNames.height = [str heightForWid:(kSize.width - 60) Font:13]+15;
-
- [self getTopicComments];
- }];
- }
- /**
- */
- -(void)uploadTopicReportInfo:(NSString*)type
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- // if (!_topicId) {
- // _topicId = _preDict[@"ID"];
- // }
-
- NSMutableArray *arr = [NSMutableArray array];
- [arr addPro:@"topicId" Value:_topicId];
- [arr addPro:@"type" Value:type];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"uploadTopicReportInfo";
- [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 ;
- }
-
- ShowMsgSuc();
- }];
- }
- /**收藏某个话题
- */
- -(void)uploadTopicFav
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (!_topicId) {
- _topicId = @"1";
- }
-
- NSMutableArray *arr = [NSMutableArray array];
- [arr addPro:@"topicId" Value:_topicId];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"uploadTopicFav";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
- //NSLog(@"收藏---->%@",dict);
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }else{
- ShowMsgSuc();
- [model setValue:@"1" forKey:@"ISFAV"];
- }
- }];
-
- }
- -(void)deleteMyTopicFav
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (!_topicId) {
- _topicId = @"1";
- }
-
- NSMutableArray *arr = [NSMutableArray array];
-
- [arr addPro:@"topicId" Value:_topicId];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"deleteMyTopicFav";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }else{
- ShowMsgSuc();
- [model setValue:@"0" forKey:@"ISFAV"];
- }
- }];
-
- }
- /**type
- 1 对话题评论
- 2 对评论进行回复
- */
- -(void)uploadTopicComment
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (!_topicId) {
- _topicId = @"1";
- }
- NSString* type;
- if (!replayUser) {
- type = @"1";
- replayUser = @"";
- }else{
- type = @"2";
- }
-
- NSMutableArray * arr = [NSMutableArray array];
- [arr addPro:@"content" Value:commentString];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"topicId" Value:_topicId];
- [arr addPro:@"type" Value:type];
- [arr addPro:@"replyUser" Value:replayUser];
-
- //NSLog(@"defUser.userDict-->%@---------replyUser-->%@",defUser.userDict[@"NICKNAME"],replayUser);
- NSString* method = @"uploadTopicComment";
- [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;
- }
- //要刷新显示
- replayUser = @"";
- //这里没必要再查话题了 耗流量
- [self getTopicComments];
- }];
-
-
- }
- -(void)uploadTopicCommentPoints
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray* arr = [NSMutableArray array];
-
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"topicId" Value:model[@"ID"]];
-
- NSString* method = @"uploadTopicCommentPoints";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- //这种处理等若没写
- if (!root) {
- ShowMsgFailed();
- return;
- }
- }];
-
- }
- -(void)deleteTopicCommentPoints
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"topicId" Value:_topicId];
-
- NSString* method = @"deleteTopicCommentPoints";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- if (!root) {
- ShowMsgFailed();
- return;
- }
- }];
- }
- -(void)deleteTopicInfo
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"id" Value:_topicId];
-
- NSString* method = @"deleteTopicInfo";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- if (!root) {
- ShowMsgFailed();
- return;
- }
- ShowMsgSuc();
- [self.navigationController popViewControllerAnimated:YES];
- }];
-
- }
- #pragma mark -
- -(void)gotoCommentsByName:(NSString *)name
- {
- if (!myDelegate.isLogin) {
- [LoginViewController loginFromVC:self];
- }else{
- replayUser = name;
- [tf becomeFirstResponder];
- }
- }
- -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (4 == buttonIndex) {
- return;
- }else{
- NSString* type = [NSString stringWithFormat:@"%d",(int)buttonIndex+19];
- [self uploadTopicReportInfo:type];
- }
- }
- -(void)userEndEdit
- {
- [tf resignFirstResponder];
-
- commentString = tf.text;
- if (commentString.length < 1) {
- return;
- }
- tf.text = @"";
- [self uploadTopicComment];
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- NSCharacterSet *whitespace=[NSCharacterSet whitespaceAndNewlineCharacterSet];
- NSString* str=[tf.text stringByTrimmingCharactersInSet:whitespace];
- if (str.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;
- }
- /**本来不想用通知中心。改用textView.delegate。
- 可是。为了动态获取键盘高度,只能用这个了。
- */
- - (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, kSize.height - kNavOffSet - 50 - kbH, kSize.width, 50);
- }];
- }
- - (void)keyboardWillHide:(NSNotification *)aNotification
- {
- [UIView animateWithDuration:.25 animations:^{
- tfContainv.frame = CGRectMake(0, kSize.height, kSize.width, 50);
- }];
- }
- #pragma mark -
- -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- if (0 == section) {
- return footer;
- }else{
- return [UIView new];
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- if (0 == section) {
- return footer.height;
- }else{
- return .1;
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return .1;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (0 == indexPath.section) {
- return communityCellHeight(model, 1);
- }else{
- return TopicComCellHeight(models[indexPath.row]);
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (0 == section) {
- return 1;
- }else{
- return models.count;
- }
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // return 2;
- return (models && models.count > 0) + 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if ( 0 == indexPath.section) {
- CommunityCell* cell = [CommunityCell cellForTableView:tableView Style:1];
- cell.block = ^{
- [tf resignFirstResponder];
- };
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- [cell setModel:model];
- [cell setShowTag:YES];
- //用于查看学车日记
- [cell setDelegate:self];
- return cell;
- }
- if (models.count > indexPath.row) {
- TopicComCell* cell = [TopicComCell cellForTableView:tableView ];
- cell.isAdopt = isUser;
- [cell setModel:models[indexPath.row]];
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- [cell setDelegate:self];
- return cell;
- }
-
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"qiguaide"];
- return cell;
- }
- //表在滑动的时候触发的方法
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)])
- {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([cell respondsToSelector:@selector(setLayoutMargins:)])
- {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- [tf resignFirstResponder];
- }
- @end
|