ReleaseresultsViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //
  2. // ReleaseresultsViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/1/16.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "ReleaseresultsViewController.h"
  9. #import "ReleaseresultsCell.h"
  10. #import "ResultsdescriptionCell.h"//
  11. #import "ResultsTitleCell.h"
  12. #define Start_X 15 // 第一个按钮的X坐标
  13. #define Start_Y 10.0f // 第一个按钮的Y坐标
  14. #define Width_Space 10.0f // 2个按钮之间的横间距
  15. #define Height_Space 10.0f // 竖间距
  16. #define Button_Height 30.0f // 高
  17. //#define Button_Width (SCREEN_WIDTH-60)/4 // 宽
  18. #define Button_Width 60 // 宽
  19. @interface ReleaseresultsViewController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate,UITextFieldDelegate>{
  20. UITableView *newtableView;
  21. NSMutableArray *dataArray;
  22. NSMutableArray *titledataArray;//标题数组
  23. NSMutableArray *updateArr;
  24. NSString *descriptionStr;//成果描述 接收字符串
  25. NSString *resultsTitleStr;//成果标题 接收字符
  26. UIButton *updatefrequencybtn;//更新频率
  27. BOOL isseemore;//查看更多
  28. NSString *technicaltypeStr;
  29. NSString *technicaltypeTag;
  30. }
  31. @end
  32. @implementation ReleaseresultsViewController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. [self setNavTitle:@"发布成果"];
  36. [self dataInitialization];
  37. [self Networkrequest];
  38. [self loadsView];
  39. // Do any additional setup after loading the view.
  40. }
  41. - (void)dataInitialization {
  42. isseemore = YES;
  43. dataArray = NewMutableArrayInit;
  44. titledataArray = [NSMutableArray arrayWithObjects:@"成果描述",@"成果标题",@"技术类型",@"其他",@"成果配图", nil];
  45. NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
  46. updateArr = [NSMutableArray arrayWithArray:arr];
  47. }
  48. - (void)Networkrequest {
  49. }
  50. #pragma mark ----加载界面
  51. - (void)loadsView{
  52. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewLineGrayColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  53. newtableView.separatorStyle = NO;
  54. }
  55. #pragma mark-------------------------UITableView------------------------------------
  56. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  57. {
  58. return 5;
  59. }
  60. //返回每段行数
  61. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  62. {
  63. if (section == 0||section == 1||section == 2) {
  64. return 1;
  65. }else if (section == 3){
  66. return 4;
  67. }
  68. return 3;
  69. }
  70. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. static NSString *Cell = @"Cell";
  73. static NSString *Cell1 = @"Cell1";
  74. static NSString *Cell2 = @"Cell2";
  75. if (indexPath.section == 0) {
  76. ResultsdescriptionCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  77. if (cell == nil) {
  78. cell = [[ResultsdescriptionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  79. }
  80. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  81. cell.accessoryType = UITableViewCellAccessoryNone;
  82. // [cell assignment:dataArray[indexPath.row]];
  83. cell.backgroundColor = NewLineGrayColor;
  84. cell.textview.delegate = self;
  85. return cell;
  86. }else if (indexPath.section == 1){
  87. ResultsTitleCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1];
  88. if (cell == nil) {
  89. cell = [[ResultsTitleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1];
  90. }
  91. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  92. cell.accessoryType = UITableViewCellAccessoryNone;
  93. cell.backgroundColor = NewLineGrayColor;
  94. [cell.textfield addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
  95. return cell;
  96. }else if (indexPath.section == 2){
  97. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1];
  98. if (cell == nil) {
  99. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1];
  100. }
  101. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  102. cell.accessoryType = UITableViewCellAccessoryNone;
  103. cell.backgroundColor = NewLineGrayColor;
  104. if (isseemore) {
  105. NSLog(@"更多1");
  106. NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
  107. [updateArr removeAllObjects];
  108. updateArr = [NSMutableArray arrayWithArray:arr];
  109. }else{
  110. NSLog(@"更多2");
  111. NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
  112. [updateArr removeAllObjects];
  113. updateArr = [NSMutableArray arrayWithArray:arr];
  114. }
  115. UIView *view = [[UIView alloc] init];
  116. CGFloat page = updateArr.count/4;
  117. view.frame = CGRectMake(0, 0, SCREEN_WIDTH, page * (Button_Height + Height_Space)+10);
  118. view.backgroundColor = NewLineGrayColor;
  119. [cell.contentView addSubview:view];
  120. for (int i = 0; i<updateArr.count; i++) {
  121. NSInteger num = 4;//每排4个
  122. NSInteger index = i % num;//每排4个
  123. NSInteger page = i / num;//
  124. UIButton *button = [UIButton new];
  125. if ([technicaltypeTag isEqualToString:[NSString stringWithFormat:@"%d",i]]) {
  126. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  127. [button setTitle:updateArr[i] forState:UIControlStateNormal];
  128. [button setBackgroundColor:NewButtonColor];
  129. ViewBorderRadius(button, 10, 0.6, NewButtonColor);
  130. }else{
  131. [button setTitle:updateArr[i] forState:UIControlStateNormal];
  132. [button setTitleColor:NewButtonColor forState:UIControlStateNormal];
  133. [button setBackgroundColor:NewWhiteColor];
  134. ViewBorderRadius(button, 10, .6, NewButtonColor);
  135. }
  136. button.tag = i;
  137. [button addTarget:self action:@selector(updatefrequencybtnclick:) forControlEvents:UIControlEventTouchUpInside];
  138. button.frame = CGRectMake(index * (fitScreenWidth(80) + fitScreenWidth(Width_Space)) + Start_X, page * (Button_Height + Height_Space)+10, fitScreenWidth(80), Button_Height);
  139. button.titleLabel.font = NewFont(fitScreenWidth(12));
  140. [view addSubview:button];
  141. }
  142. return cell;
  143. }else if (indexPath.section == 3){
  144. ReleaseresultsCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell2];
  145. if (cell == nil) {
  146. cell = [[ReleaseresultsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell2];
  147. }
  148. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  149. cell.accessoryType = UITableViewCellAccessoryNone;
  150. cell.backgroundColor = NewWhiteColor;
  151. if (indexPath.row == 0) {
  152. cell.line.hidden = NO;
  153. cell.title.text = @"所在地";
  154. }else{
  155. cell.line.hidden = YES;
  156. cell.title.text = @"行 业";
  157. }
  158. if (indexPath.row == 0) {
  159. }else{
  160. cell.textfield.placeholder = @"环保和资源";
  161. }
  162. // [cell assignment:dataArray[indexPath.row]];
  163. return cell;
  164. }
  165. return [[UITableViewCell alloc] init];
  166. }
  167. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  168. {
  169. if (indexPath.section == 0) {
  170. return fitScreenWidth(134);
  171. }else if (indexPath.section == 1){
  172. return fitScreenWidth(64);
  173. }else if (indexPath.section == 2){
  174. if (isseemore) {
  175. NSLog(@"更多1");
  176. NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
  177. [updateArr removeAllObjects];
  178. updateArr = [NSMutableArray arrayWithArray:arr];
  179. CGFloat page = updateArr.count/4;
  180. return page * (Button_Height + Height_Space)+10;
  181. }else{
  182. NSLog(@"更多2");
  183. NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
  184. [updateArr removeAllObjects];
  185. updateArr = [NSMutableArray arrayWithArray:arr];
  186. CGFloat page = updateArr.count/4;
  187. return page * (Button_Height + Height_Space)+10;
  188. }
  189. }else if (indexPath.section == 3){
  190. if (indexPath.row == 0||indexPath.row == 1) {
  191. return 10+fitScreenWidth(44)+5;
  192. }
  193. return 10;
  194. }
  195. return fitScreenWidth(44);
  196. }
  197. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  198. }
  199. // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
  200. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  201. if (section == 0) {
  202. return fitScreenWidth(44)+10;
  203. }
  204. return fitScreenWidth(44);
  205. }
  206. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  207. return CGFLOAT_MIN;
  208. }
  209. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  210. static NSString * identy = @"head";
  211. UITableViewHeaderFooterView * hf = [tableView dequeueReusableHeaderFooterViewWithIdentifier:identy];
  212. NSLog(@"%li",section);
  213. hf = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:identy];
  214. UIView * view = [[UIView alloc]init];
  215. view.backgroundColor = [UIColor whiteColor];
  216. if (section == 0) {
  217. view.frame = CGRectMake(0, 10, SCREEN_WIDTH, fitScreenWidth(44));
  218. }else{
  219. view.frame = CGRectMake(0, 0, SCREEN_WIDTH, fitScreenWidth(44));
  220. }
  221. [hf addSubview:view];
  222. UILabel *line = [UILabel new];
  223. line.backgroundColor = NewButtonColor;
  224. ViewRadius(line, 1);
  225. [view addSubview:line];
  226. line.sd_layout
  227. .leftSpaceToView(view, 15)
  228. .centerYEqualToView(view)
  229. .heightIs(fitScreenWidth(18))
  230. .widthIs(3);
  231. UILabel *title = [UILabel new];
  232. [title setText:titledataArray[section]];
  233. [title setFont:NewFont(fitScreenWidth(13))];
  234. [title setSingleLineAutoResizeWithMaxWidth:0];
  235. [view addSubview:title];
  236. title.sd_layout
  237. .leftSpaceToView(line, 7)
  238. .heightIs(fitScreenWidth(44))
  239. .topEqualToView(view)
  240. .centerYEqualToView(view);
  241. UIButton *seemore = [UIButton new];
  242. [seemore setBackgroundColor:NewRedColor];
  243. [seemore setImage:[UIImage imageNamed:@"发现-科技成果"] forState:UIControlStateNormal];
  244. [seemore setImage:[UIImage imageNamed:@"发现-科技需求"] forState:UIControlStateSelected];
  245. NewTouchUpInside(seemore, seemoreclick:);
  246. [view addSubview:seemore];
  247. seemore.sd_layout
  248. .rightSpaceToView(view, 15)
  249. .heightIs(30)
  250. .widthIs(50)
  251. .centerYEqualToView(view);
  252. if (section == 2) {
  253. seemore.hidden = NO;
  254. }else{
  255. seemore.hidden = YES;
  256. }
  257. return hf;
  258. }
  259. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  260. return [[UIView alloc] init];
  261. }
  262. #pragma mark - UITextView获得焦点之后,并且已经是第一响应者
  263. -(void)textViewDidBeginEditing:(UITextView *)textView
  264. {
  265. // NSLog(@"UITextView获得焦点之后,并且已经是第一响应者");
  266. if ([textView.text isEqualToString:@"请描述您的技术成果~"]) {
  267. textView.text = @"";
  268. textView.textColor = NewGrayColor;
  269. }
  270. }
  271. #pragma mark - UITextView失去焦点之后
  272. -(void)textViewDidEndEditing:(UITextView *)textView
  273. {
  274. //NSLog(@"UITextView失去焦点");
  275. if ([textView.text isEqualToString:@""] || textView.text.length == 0) {
  276. textView.text = @"请描述您的技术成果~";
  277. textView.textColor = NewRGBColor(199, 199, 205, 1);
  278. }
  279. }
  280. #pragma mark - 详细地址限制字数
  281. -(void)textViewDidChangeSelection:(UITextView *)textView
  282. {
  283. if(textView.text.length > 500){
  284. textView.text = [textView.text substringWithRange:NSMakeRange(0,500)];
  285. }
  286. if (textView.text.length > 0) {
  287. NSLog(@"textView.text:%@",textView.text);
  288. if ([textView.text isEqualToString:@"请描述您的技术成果~"]) {
  289. descriptionStr = @"";
  290. }else{
  291. descriptionStr = nil;
  292. descriptionStr = textView.text;
  293. }
  294. }
  295. }
  296. #pragma mark - TextField作字符输入限制
  297. - (void)textFieldEditingChanged:(UITextField *)textField
  298. {
  299. if ([textField.text length]>50) {
  300. UITextRange *markedRange = [textField markedTextRange];
  301. if (markedRange) {
  302. return;
  303. }
  304. NSRange range = [textField.text rangeOfComposedCharacterSequenceAtIndex:50];
  305. textField.text = [textField.text substringToIndex:range.location];
  306. [self.view makeToast:@"标题最多输入50个字哦~" duration:1.5 position:CSToastPositionCenter];
  307. }
  308. resultsTitleStr = textField.text;
  309. NSLog(@"%@",resultsTitleStr);
  310. }
  311. - (void)seemoreclick:(UIButton *)sender {
  312. NSLog(@"点击查看更多");
  313. sender.selected = !sender.selected;
  314. if (!sender.selected) {
  315. isseemore = YES;
  316. }else{
  317. isseemore = NO;
  318. }
  319. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
  320. [newtableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
  321. // updatefrequencybtn = nil;
  322. }
  323. - (void)updatefrequencybtnclick:(UIButton *)sender {
  324. if(updatefrequencybtn == sender) {
  325. //针对最后一个按钮创建
  326. NSLog(@"1111");
  327. } else{
  328. //本次点击的按钮设为白色
  329. [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  330. [sender setBackgroundColor:NewButtonColor];
  331. ViewBorderRadius(sender, 10, 0.6, NewButtonColor);
  332. //将上次点击过的按钮设为蓝色
  333. [updatefrequencybtn setTitleColor:NewButtonColor forState:UIControlStateNormal];
  334. [updatefrequencybtn setBackgroundColor:NewWhiteColor];
  335. ViewBorderRadius(updatefrequencybtn, 10, 0.6, NewButtonColor);
  336. }
  337. updatefrequencybtn = sender;
  338. technicaltypeTag = [NSString stringWithFormat:@"%ld",sender.tag];
  339. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
  340. [newtableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
  341. NSLog(@"%@",technicaltypeStr);
  342. }
  343. - (void)didReceiveMemoryWarning {
  344. [super didReceiveMemoryWarning];
  345. // Dispose of any resources that can be recreated.
  346. }
  347. /*
  348. #pragma mark - Navigation
  349. // In a storyboard-based application, you will often want to do a little preparation before navigation
  350. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  351. // Get the new view controller using [segue destinationViewController].
  352. // Pass the selected object to the new view controller.
  353. }
  354. */
  355. @end