TopicVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. //
  2. #import "TopicVC.h"
  3. #import "CommunityCell.h"
  4. #import "TopicComCell.h"
  5. #import "STButton.h"
  6. #import "LoginViewController.h"
  7. @interface TopicVC () <UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,UIActionSheetDelegate,TopicComCellDelegate,CommunityCellDelegate>
  8. {
  9. /**输入框的父视图
  10. */
  11. UIView* tfContainv;
  12. UITextView* tf;
  13. /**“发送”按钮
  14. */
  15. UIButton* postBtn;
  16. UITableView* myTableView;
  17. /**仅仅是某话题的详情
  18. */
  19. NSDictionary* model;
  20. /**某话题的评论列表列表
  21. */
  22. NSArray* models;
  23. /**全屏的阴影按钮
  24. */
  25. UIView *shadowView;
  26. /**下方的点赞按钮。保存引用,以便于修改
  27. */
  28. STButton* favBtn;
  29. /**收藏按钮。不是点赞
  30. */
  31. STButton* storeBtn;
  32. /**下方的评论按钮。保存引用,以便于修改
  33. */
  34. STButton* comBtn;
  35. /**显示有多少条评论,以及评论人数。
  36. */
  37. UIView* footer;
  38. UILabel* lblNames,*lblComCnt;
  39. /**当用户点击cell的评论按钮时,传来一个用户ID。需要保存在这里。
  40. */
  41. NSString* replayUser;
  42. //判断是否是话题拥有者
  43. BOOL isUser;
  44. //输入框内容
  45. NSString *commentString;
  46. }
  47. @end
  48. @implementation TopicVC
  49. -(void)dealloc{
  50. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  51. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  52. }
  53. /**考虑到这个VC的表结构的问题。先去设置导航右按钮
  54. */
  55. - (void)viewDidLoad
  56. {
  57. [super viewDidLoad];
  58. [self myInit];
  59. }
  60. - (void)didReceiveMemoryWarning
  61. {
  62. [super didReceiveMemoryWarning];
  63. }
  64. -(void)viewDidAppear:(BOOL)animated
  65. {
  66. [super viewDidAppear:animated];
  67. [self getTopicInfo];
  68. if (_textViewActive) {
  69. _textViewActive = NO;
  70. [tf becomeFirstResponder];
  71. }
  72. }
  73. #pragma mark -
  74. -(void)myInit
  75. {
  76. [self setTitle:@"话题详情"];
  77. [self.view setBackgroundColor:[UIColor whiteColor]];
  78. if (_isNotification == NO)
  79. {
  80. //正常状态
  81. [self configNavigationBar];
  82. }
  83. else
  84. {
  85. //推送状态 要将根视图变回去
  86. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  87. [backBtn setTintColor:defGreen];
  88. self.navigationController.navigationBar.translucent = NO;
  89. [self.navigationItem setLeftBarButtonItem:backBtn];
  90. }
  91. /**配置导航右按钮
  92. */
  93. UIBarButtonItem *backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"community3.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnClick:)];
  94. [backBbi setTintColor:defGreen];
  95. [backBbi setTag:2];
  96. [self.navigationItem setRightBarButtonItem:backBbi];
  97. CGFloat x,y,w,h,bd;
  98. NSInteger tag = 0;
  99. //配置bottombar
  100. CGFloat barH = 65;
  101. x = 0;
  102. y = 0;
  103. w = kSize.width;
  104. h = kSize.height - kNavOffSet - kSafeAreaBottomHeight - barH;
  105. UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped];
  106. tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, .1)];
  107. [self.view addSubview:tv];
  108. [tv setBackgroundColor:[UIColor whiteColor]];
  109. tv.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  110. myTableView = tv;
  111. [myTableView setDelegate:self];
  112. [myTableView setDataSource:self];
  113. myTableView.estimatedSectionHeaderHeight = 0;
  114. [tv setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
  115. if ([tv respondsToSelector:@selector(setSeparatorInset:)])
  116. {
  117. [tv setSeparatorInset:UIEdgeInsetsZero];
  118. }
  119. if ([tv respondsToSelector:@selector(setLayoutMargins:)])
  120. {
  121. [tv setLayoutMargins:UIEdgeInsetsZero];
  122. }
  123. y+=h;
  124. h = barH;
  125. tfContainv = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, h)];
  126. //NSLog(@"%@",NSStringFromCGRect(tfContainv.frame));
  127. [tfContainv setBackgroundColor:backGroundColor];
  128. [self.view addSubview:tfContainv];
  129. UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, h)];
  130. [vi setBackgroundColor:backGroundColor];
  131. [self.view addSubview:vi];
  132. // vi.hidden= YES;
  133. w = 50;
  134. bd = 10;
  135. tf = [[UITextView alloc] initWithFrame:CGRectMake(bd, (50 - 25)/2, kSize.width-bd*3 - w, 25)];
  136. [tf setFont:[UIFont scaleSize:NormalFont]];
  137. [tf setFont:[UIFont scaleSize:15]];
  138. [tfContainv addSubview:tf];
  139. [tf setDelegate:self];
  140. // [tfContainv addSelfViewWithRect:CGRectMake(bd, 25/2+25+1, kSize.width-bd*3 - w-4, 1) Color:defGreen];
  141. //注册通知
  142. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  143. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  144. UIButton* btn =[[UIButton alloc] initWithFrame:CGRectMake(kSize.width - w - bd, (50 - 30)/2, w, 30)];
  145. [btn setTitle:@"发送" textColor:backGroundColor font:NormalFont fotState:UIControlStateNormal];
  146. [btn addTarget:self action:@selector(userEndEdit) forControlEvents:UIControlEventTouchUpInside];
  147. [btn setBackgroundColor:[UIColor grayColor]];
  148. [btn.layer setCornerRadius:5];
  149. [btn.layer setMasksToBounds:YES];
  150. postBtn = btn;
  151. [tfContainv addSubview: btn];
  152. w = h*1.3;
  153. bd = (kSize.width - w*2)/5.0;
  154. x = bd*2;
  155. STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, 0, w, h)];
  156. [stBtn setStyle:1];
  157. [stBtn setImage:[UIImage imageNamed:@"community0.png"] withTitle:@"" Font:SmallFont forState:UIControlStateNormal];
  158. [stBtn setImage:[UIImage imageNamed:@"community1.png"] forState:UIControlStateSelected];
  159. [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  160. [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  161. [vi addSubview:stBtn];
  162. favBtn = stBtn;
  163. [stBtn setTag:tag++];//0
  164. x +=bd+w;
  165. stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, 0, w, h)];
  166. [stBtn setStyle:1];
  167. [stBtn setImage:[UIImage imageNamed:@"community2.png"] withTitle:@"评论" Font:SmallFont forState:UIControlStateNormal];
  168. [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  169. [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  170. [vi addSubview:stBtn];
  171. comBtn = stBtn;
  172. [stBtn setTag:1];
  173. /**tableView创建
  174. */
  175. vi = [[UIView alloc] init];
  176. [vi setBackgroundColor:[UIColor whiteColor]];
  177. footer = vi;
  178. UILabel* label;
  179. label = [[UILabel alloc] init];
  180. [vi addSubview:label];
  181. [label setTextColor:defGreen];
  182. [label setFont:[UIFont scaleSize:13]];
  183. label.numberOfLines = 0;
  184. lblNames = label;
  185. label = [[UILabel alloc] init];
  186. [vi addSubview:label];
  187. lblComCnt = label;
  188. [label setTextColor:contentTextColor];
  189. [label setFont:[UIFont scaleSize:13]];
  190. }
  191. -(void)dismissNavgation
  192. {
  193. //推送过来 返回主页面
  194. [myDelegate gotoLoad];
  195. }
  196. -(void)btnClick:(UIButton*)sender
  197. {
  198. NSInteger tag = sender.tag;
  199. if (0 == tag ||5 == tag ||6 == tag) {
  200. if (!myDelegate.isLogin) {
  201. [LoginViewController loginFromVC:self];
  202. return;
  203. }
  204. }
  205. if (0 == tag) {
  206. //话题点赞
  207. int num = [model[@"POINTNUM"] intValue] - [model[@"ISPOINT"] intValue];
  208. if (sender.selected) {
  209. [sender setTitle:[NSString stringWithFormat:@"赞(%d)",num] forState:UIControlStateNormal];
  210. [self deleteTopicCommentPoints];
  211. }else{
  212. [sender setTitle:[NSString stringWithFormat:@"赞(%d)",num+1] forState:UIControlStateNormal];
  213. [self uploadTopicCommentPoints];
  214. }
  215. sender.selected = !sender.selected;
  216. }
  217. if (1 == tag) {
  218. if (!myDelegate.isLogin) {
  219. LoginViewController* vc = [[LoginViewController alloc] init];
  220. vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  221. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  222. [self presentViewController:vc animated:YES completion:nil];
  223. }else{
  224. //展示输入框。
  225. [tf becomeFirstResponder];
  226. }
  227. }
  228. if ( 2 == tag) {
  229. [tf resignFirstResponder];
  230. if (shadowView) {
  231. //慢慢消失
  232. [self hideMenu];
  233. }else{
  234. //慢慢出现
  235. shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, -80, kSize.width, kSize.height)];
  236. shadowView.backgroundColor = [UIColor colorWithWhite:.1 alpha:0.42];
  237. [self.view addSubview:shadowView];
  238. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideMenu)];
  239. [shadowView addGestureRecognizer:tap];
  240. NSArray* titles;
  241. NSArray* images;
  242. if(isUser) {
  243. titles= @[@"删除",@"收藏"];
  244. images = @[@"community6.png",@"Topic_img03.png"];
  245. }else{
  246. titles= @[@"举报",@"收藏",@"屏蔽此人",@"屏蔽此条"];
  247. images = @[@"Topic_img02.png",@"Topic_img03.png",@"Topic_img02.png",@"Topic_img02.png"];
  248. }
  249. CGFloat w = kSize.width / titles.count;
  250. for (int i = 0; i<titles.count; i++) {
  251. STButton *stBtn = [[STButton alloc] initWithFrame:CGRectMake( w*i, 0, w, 80)];
  252. [stBtn setImage:[UIImage imageNamed:images[i]] withTitle:titles[i] Font:13 forState:UIControlStateNormal];
  253. [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  254. [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  255. [stBtn setBackgroundColor:[UIColor whiteColor]];
  256. [stBtn setTag:i + 5];
  257. [shadowView addSubview:stBtn];
  258. if (1 == i) {
  259. [stBtn setImage:[[UIImage imageNamed:images[1]] tint:defGreen] withTitle:@"取消收藏" Font:13 forState:UIControlStateSelected];
  260. [stBtn setTitleColor:defGreen forState:UIControlStateSelected];
  261. storeBtn = stBtn;
  262. if ([model[@"ISFAV"] integerValue] != 0)
  263. {
  264. storeBtn.selected = YES;
  265. }else{
  266. storeBtn.selected = NO;
  267. }
  268. }
  269. }
  270. // [shadowView addSelfViewWithRect:CGRectMake( w, 0, 1, 80) Color:KlineColor];
  271. [UIView animateWithDuration:.5 animations:^{
  272. shadowView.alpha = 1;
  273. shadowView.frame = kFrame;
  274. }];
  275. }
  276. }
  277. if ( 3 == tag) {
  278. //不用做隐藏操作
  279. //[self hideMenu];
  280. }
  281. if (5 == tag) {
  282. [self hideMenu];
  283. if (!isUser) {
  284. //举报
  285. UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"请选择举报类型" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"敏感话题",@"淫秽色情",@"垃圾广告",@"人身攻击", nil];
  286. [sheet setDelegate:self];
  287. [sheet showInView:self.view];
  288. }else{
  289. [self deleteTopicInfo];
  290. }
  291. }
  292. if (6 == tag) {
  293. //收藏
  294. [self hideMenu];
  295. if (sender.selected) {
  296. //取消
  297. [self deleteMyTopicFav];
  298. }else{
  299. //添加
  300. [self uploadTopicFav];
  301. }
  302. sender.selected = !sender.selected;
  303. }
  304. if (7 == tag) {
  305. NSMutableArray *arr = [NSMutableArray arrayWithArray:RQ_SHARE_FUNCTION.shieldPeopleIDArr];
  306. if (![arr containsObject:_userId]) {
  307. [arr addObject:_userId];
  308. RQ_SHARE_FUNCTION.shieldPeopleIDArr = arr.copy;
  309. }
  310. [self hideMenuAndPop];
  311. }
  312. if (tag == 8) {
  313. NSMutableArray *arr = [NSMutableArray arrayWithArray:RQ_SHARE_FUNCTION.shieldTopicIDArr];
  314. if (![arr containsObject:_topicId]) {
  315. [arr addObject:_topicId];
  316. RQ_SHARE_FUNCTION.shieldTopicIDArr = arr.copy;
  317. }
  318. [self hideMenuAndPop];
  319. }
  320. if (9 <= tag && tag <= 12) {
  321. [self hideMenu];
  322. ShowMsgUnOpen();
  323. }
  324. }
  325. -(void)hideMenu
  326. {
  327. [UIView animateWithDuration:.5 animations:^{
  328. shadowView.alpha = 0;
  329. shadowView.frame = CGRectMake(0, -80, kSize.width, kSize.height);
  330. } completion:^(BOOL finished) {
  331. [shadowView removeFromSuperview];
  332. shadowView = nil;
  333. }];
  334. }
  335. -(void)hideMenuAndPop
  336. {
  337. [UIView animateWithDuration:.5 animations:^{
  338. shadowView.alpha = 0;
  339. shadowView.frame = CGRectMake(0, -80, kSize.width, kSize.height);
  340. } completion:^(BOOL finished) {
  341. [shadowView removeFromSuperview];
  342. shadowView = nil;
  343. [self.navigationController popViewControllerAnimated:YES];
  344. }];
  345. }
  346. #pragma mark -
  347. /**获取话题详情
  348. */
  349. -(void)getTopicInfo
  350. {
  351. if (![Util connectedToNetWork]) {
  352. showMsgUnconnect();
  353. return;
  354. }
  355. NSMutableArray *arr=[NSMutableArray array];
  356. [arr addPro:@"id" Value:_topicId];
  357. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  358. NSString* method = @"getTopicInfo";
  359. [MBProgressHUD showLoadToView:self.view];
  360. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  361. [MBProgressHUD hideHUDForView:self.view];
  362. if (!dict) {
  363. ShowMsgFailed();
  364. return;
  365. }
  366. if (![dict[@"code"] isEqualToString:@"0"]) {
  367. ShowMsg(dict[@"body"]);
  368. return;
  369. }
  370. if (![dict isKindOfClass:[NSDictionary class]]) {
  371. ShowMsg(@"数据异常");
  372. return;
  373. }
  374. //这里要加个判断 防止从话题进入学车日记 对该条话题进行删除操作 在返回的时候自动查询返回为空导致crash
  375. if ([dict[@"body"] isKindOfClass:[NSDictionary class]]) {
  376. if ([dict[@"body"] allKeys].count != 0) {
  377. model = (NSDictionary *)dict[@"body"];
  378. _userId = model[@"CRUSER"];
  379. }
  380. }
  381. [myTableView reloadData];
  382. [self getTopicPoints];
  383. //判断是否是本人
  384. if ([defUser.userDict[@"id"] isEqualToString:model[@"CRUSER"]]) {
  385. isUser = YES;
  386. }else{
  387. isUser = NO;
  388. }
  389. //判断是否已点过赞
  390. NSString* str = [NSString stringWithFormat:@"赞(%@)",model[@"POINTNUM"]];
  391. [favBtn setTitle:str forState:UIControlStateNormal];
  392. if ([model[@"ISPOINT"] integerValue]) {
  393. [favBtn setSelected:YES];
  394. }else{
  395. [favBtn setSelected:NO];
  396. }
  397. }];
  398. }
  399. -(void)getTopicComments
  400. {
  401. if (![Util connectedToNetWork]) {
  402. showMsgUnconnect();
  403. return;
  404. }
  405. if (!_topicId) {
  406. _topicId = @"1";
  407. }
  408. NSMutableArray *arr=[NSMutableArray array];
  409. [arr addPro:@"topicId" Value:_topicId];
  410. [arr addPro:@"isPage" Value:@""];
  411. [arr addPro:@"pageSize" Value:@""];
  412. [arr addPro:@"currentPage" Value:@""];
  413. NSString* method = @"getTopicComments";
  414. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  415. if (!dict) {
  416. ShowMsgFailed();
  417. return;
  418. }
  419. if ( [dict[@"code"] isEqualToString:@"1"]) {
  420. ShowMsg(dict[@"body"]);
  421. return;
  422. }
  423. models = dict[@"body"];
  424. //NSLog(@"返回评论列表------>%@",models);
  425. [lblComCnt setText:[NSString stringWithFormat:@"%d条评论",(int)models.count]];
  426. lblComCnt.frame = CGRectMake(10, lblNames.bottom, kSize.width, 30);
  427. [lblComCnt addViewWithRect:CGRectMake(10, lblNames.bottom, kSize.width-20, 1)];
  428. [comBtn setTitle:[NSString stringWithFormat:@"评论(%d)",(int)models.count] forState:UIControlStateNormal];
  429. footer.frame = CGRectMake(0, 0, kSize.width, lblComCnt.bottom);
  430. //要先改footer再刷新表 要不然 返回的区尾尺寸不对
  431. [myTableView reloadData];
  432. }];
  433. }
  434. /**获取点赞用户列表
  435. */
  436. -(void)getTopicPoints
  437. {
  438. if (![Util connectedToNetWork]) {
  439. showMsgUnconnect();
  440. return;
  441. }
  442. NSMutableArray *arr=[NSMutableArray array];
  443. [arr addPro:@"topicId" Value:_topicId];
  444. NSString* method = @"getTopicPoints";
  445. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  446. if (!dict) {
  447. ShowMsg(@"获取点赞列表失败!");
  448. lblNames.frame = CGRectMake(10, 0, kSize.width - 60, 30);
  449. [self getTopicComments];
  450. return;
  451. }
  452. if ( [dict[@"code"] isEqualToString:@"1"]) {
  453. ShowMsg(dict[@"body"]);
  454. lblNames.frame = CGRectMake(10, 0, kSize.width - 60, 30);
  455. [self getTopicComments];
  456. return;
  457. }
  458. NSArray *array = dict[@"body"];
  459. //NSLog(@"获取话题赞数---->%@",array);
  460. NSMutableString* str = [NSMutableString string];
  461. for (int i =0;i < array.count;i++) {
  462. if ( i < array.count - 1) {
  463. [str appendFormat:@"%@,",[array[i] objectForKey:@"NICKNAME"]];
  464. }else{
  465. [str appendFormat:@"%@ 等%d人赞过",[array[i] objectForKey:@"NICKNAME"],(int)array.count];
  466. }
  467. }
  468. if (array.count < 1) {
  469. [lblNames setText:@"还没人赞过呢"];
  470. }else{
  471. [lblNames setText:str];
  472. }
  473. //为了更好看。高度30是随意设置的。真正的高度是在下面一行计算的。
  474. lblNames.frame = CGRectMake(10, 0, kSize.width - 60, 30);
  475. lblNames.height = [str heightForWid:(kSize.width - 60) Font:13]+15;
  476. [self getTopicComments];
  477. }];
  478. }
  479. /**
  480. */
  481. -(void)uploadTopicReportInfo:(NSString*)type
  482. {
  483. if (![Util connectedToNetWork]) {
  484. showMsgUnconnect();
  485. return;
  486. }
  487. // if (!_topicId) {
  488. // _topicId = _preDict[@"ID"];
  489. // }
  490. NSMutableArray *arr = [NSMutableArray array];
  491. [arr addPro:@"topicId" Value:_topicId];
  492. [arr addPro:@"type" Value:type];
  493. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  494. NSString* method = @"uploadTopicReportInfo";
  495. [MBProgressHUD showLoadToView:self.view];
  496. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  497. [MBProgressHUD hideHUDForView:self.view];
  498. if (!dict) {
  499. ShowMsgFailed();
  500. return ;
  501. }
  502. if ( [dict[@"code"] isEqualToString:@"1"]) {
  503. ShowMsg(dict[@"body"]);
  504. return ;
  505. }
  506. ShowMsgSuc();
  507. }];
  508. }
  509. /**收藏某个话题
  510. */
  511. -(void)uploadTopicFav
  512. {
  513. if (![Util connectedToNetWork]) {
  514. showMsgUnconnect();
  515. return;
  516. }
  517. if (!_topicId) {
  518. _topicId = @"1";
  519. }
  520. NSMutableArray *arr = [NSMutableArray array];
  521. [arr addPro:@"topicId" Value:_topicId];
  522. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  523. NSString* method = @"uploadTopicFav";
  524. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  525. //NSLog(@"收藏---->%@",dict);
  526. if (!dict) {
  527. ShowMsgFailed();
  528. return;
  529. }
  530. if ( [dict[@"code"] isEqualToString:@"1"]) {
  531. ShowMsg(dict[@"body"]);
  532. return;
  533. }else{
  534. ShowMsgSuc();
  535. [model setValue:@"1" forKey:@"ISFAV"];
  536. }
  537. }];
  538. }
  539. -(void)deleteMyTopicFav
  540. {
  541. if (![Util connectedToNetWork]) {
  542. showMsgUnconnect();
  543. return;
  544. }
  545. if (!_topicId) {
  546. _topicId = @"1";
  547. }
  548. NSMutableArray *arr = [NSMutableArray array];
  549. [arr addPro:@"topicId" Value:_topicId];
  550. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  551. NSString* method = @"deleteMyTopicFav";
  552. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  553. if (!dict) {
  554. ShowMsgFailed();
  555. return;
  556. }
  557. if ( [dict[@"code"] isEqualToString:@"1"]) {
  558. ShowMsg(dict[@"body"]);
  559. return;
  560. }else{
  561. ShowMsgSuc();
  562. [model setValue:@"0" forKey:@"ISFAV"];
  563. }
  564. }];
  565. }
  566. /**type
  567. 1 对话题评论
  568. 2 对评论进行回复
  569. */
  570. -(void)uploadTopicComment
  571. {
  572. if (![Util connectedToNetWork]) {
  573. showMsgUnconnect();
  574. return;
  575. }
  576. if (!_topicId) {
  577. _topicId = @"1";
  578. }
  579. NSString* type;
  580. if (!replayUser) {
  581. type = @"1";
  582. replayUser = @"";
  583. }else{
  584. type = @"2";
  585. }
  586. NSMutableArray * arr = [NSMutableArray array];
  587. [arr addPro:@"content" Value:commentString];
  588. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  589. [arr addPro:@"topicId" Value:_topicId];
  590. [arr addPro:@"type" Value:type];
  591. [arr addPro:@"replyUser" Value:replayUser];
  592. //NSLog(@"defUser.userDict-->%@---------replyUser-->%@",defUser.userDict[@"NICKNAME"],replayUser);
  593. NSString* method = @"uploadTopicComment";
  594. [MBProgressHUD showLoadToView:self.view];
  595. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  596. [MBProgressHUD hideHUDForView:self.view];
  597. if (!dict) {
  598. ShowMsgFailed();
  599. return;
  600. }
  601. if ( [dict[@"code"] isEqualToString:@"1"]) {
  602. ShowMsg(dict[@"body"]);
  603. return;
  604. }
  605. //要刷新显示
  606. replayUser = @"";
  607. //这里没必要再查话题了 耗流量
  608. [self getTopicComments];
  609. }];
  610. }
  611. -(void)uploadTopicCommentPoints
  612. {
  613. if (![Util connectedToNetWork]) {
  614. showMsgUnconnect();
  615. return;
  616. }
  617. NSMutableArray* arr = [NSMutableArray array];
  618. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  619. [arr addPro:@"topicId" Value:model[@"ID"]];
  620. NSString* method = @"uploadTopicCommentPoints";
  621. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  622. //这种处理等若没写
  623. if (!root) {
  624. ShowMsgFailed();
  625. return;
  626. }
  627. }];
  628. }
  629. -(void)deleteTopicCommentPoints
  630. {
  631. if (![Util connectedToNetWork]) {
  632. showMsgUnconnect();
  633. return;
  634. }
  635. NSMutableArray* arr = [NSMutableArray array];
  636. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  637. [arr addPro:@"topicId" Value:_topicId];
  638. NSString* method = @"deleteTopicCommentPoints";
  639. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  640. if (!root) {
  641. ShowMsgFailed();
  642. return;
  643. }
  644. }];
  645. }
  646. -(void)deleteTopicInfo
  647. {
  648. if (![Util connectedToNetWork]) {
  649. showMsgUnconnect();
  650. return;
  651. }
  652. NSMutableArray* arr = [NSMutableArray array];
  653. [arr addPro:@"id" Value:_topicId];
  654. NSString* method = @"deleteTopicInfo";
  655. [MBProgressHUD showLoadToView:self.view];
  656. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  657. [MBProgressHUD hideHUDForView:self.view];
  658. if (!root) {
  659. ShowMsgFailed();
  660. return;
  661. }
  662. ShowMsgSuc();
  663. [self.navigationController popViewControllerAnimated:YES];
  664. }];
  665. }
  666. #pragma mark -
  667. -(void)gotoCommentsByName:(NSString *)name
  668. {
  669. if (!myDelegate.isLogin) {
  670. [LoginViewController loginFromVC:self];
  671. }else{
  672. replayUser = name;
  673. [tf becomeFirstResponder];
  674. }
  675. }
  676. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  677. {
  678. if (4 == buttonIndex) {
  679. return;
  680. }else{
  681. NSString* type = [NSString stringWithFormat:@"%d",(int)buttonIndex+19];
  682. [self uploadTopicReportInfo:type];
  683. }
  684. }
  685. -(void)userEndEdit
  686. {
  687. [tf resignFirstResponder];
  688. commentString = tf.text;
  689. if (commentString.length < 1) {
  690. return;
  691. }
  692. tf.text = @"";
  693. [self uploadTopicComment];
  694. }
  695. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  696. {
  697. NSCharacterSet *whitespace=[NSCharacterSet whitespaceAndNewlineCharacterSet];
  698. NSString* str=[tf.text stringByTrimmingCharactersInSet:whitespace];
  699. if (str.length < 1) {
  700. [postBtn setEnabled:NO];
  701. [postBtn setBackgroundColor:[UIColor grayColor]];
  702. }else{
  703. [postBtn setEnabled:YES];
  704. [postBtn setBackgroundColor:defGreen];
  705. }
  706. if ([text isEqualToString:@"\n"]){
  707. [self userEndEdit];
  708. return NO;
  709. //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
  710. }
  711. return YES;
  712. }
  713. /**本来不想用通知中心。改用textView.delegate。
  714. 可是。为了动态获取键盘高度,只能用这个了。
  715. */
  716. - (void)keyboardWillShow:(NSNotification *)aNotification
  717. {
  718. NSDictionary *userInfo = [aNotification userInfo];
  719. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  720. CGRect keyboardRect = [aValue CGRectValue];
  721. CGFloat kbH = keyboardRect.size.height;
  722. [UIView animateWithDuration:.25 animations:^{
  723. tfContainv.frame = CGRectMake(0, kSize.height - kNavOffSet - 50 - kbH, kSize.width, 50);
  724. }];
  725. }
  726. - (void)keyboardWillHide:(NSNotification *)aNotification
  727. {
  728. [UIView animateWithDuration:.25 animations:^{
  729. tfContainv.frame = CGRectMake(0, kSize.height, kSize.width, 50);
  730. }];
  731. }
  732. #pragma mark -
  733. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  734. {
  735. if (0 == section) {
  736. return footer;
  737. }else{
  738. return [UIView new];
  739. }
  740. }
  741. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  742. {
  743. if (0 == section) {
  744. return footer.height;
  745. }else{
  746. return .1;
  747. }
  748. }
  749. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  750. {
  751. return .1;
  752. }
  753. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  754. {
  755. if (0 == indexPath.section) {
  756. return communityCellHeight(model, 1);
  757. }else{
  758. return TopicComCellHeight(models[indexPath.row]);
  759. }
  760. }
  761. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  762. {
  763. if (0 == section) {
  764. return 1;
  765. }else{
  766. return models.count;
  767. }
  768. }
  769. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  770. {
  771. // return 2;
  772. return (models && models.count > 0) + 1;
  773. }
  774. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  775. {
  776. if ( 0 == indexPath.section) {
  777. CommunityCell* cell = [CommunityCell cellForTableView:tableView Style:1];
  778. cell.block = ^{
  779. [tf resignFirstResponder];
  780. };
  781. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  782. [cell setModel:model];
  783. [cell setShowTag:YES];
  784. //用于查看学车日记
  785. [cell setDelegate:self];
  786. return cell;
  787. }
  788. if (models.count > indexPath.row) {
  789. TopicComCell* cell = [TopicComCell cellForTableView:tableView ];
  790. cell.isAdopt = isUser;
  791. [cell setModel:models[indexPath.row]];
  792. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  793. [cell setDelegate:self];
  794. return cell;
  795. }
  796. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"qiguaide"];
  797. return cell;
  798. }
  799. //表在滑动的时候触发的方法
  800. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  801. {
  802. if ([cell respondsToSelector:@selector(setSeparatorInset:)])
  803. {
  804. [cell setSeparatorInset:UIEdgeInsetsZero];
  805. }
  806. if ([cell respondsToSelector:@selector(setLayoutMargins:)])
  807. {
  808. [cell setLayoutMargins:UIEdgeInsetsZero];
  809. }
  810. }
  811. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  812. [tf resignFirstResponder];
  813. }
  814. @end