| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- //
- // ReleaseresultsViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2018/1/16.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "ReleaseresultsViewController.h"
- #import "ReleaseresultsCell.h"
- #import "ResultsdescriptionCell.h"//
- #import "ResultsTitleCell.h"
- #define Start_X 15 // 第一个按钮的X坐标
- #define Start_Y 10.0f // 第一个按钮的Y坐标
- #define Width_Space 10.0f // 2个按钮之间的横间距
- #define Height_Space 10.0f // 竖间距
- #define Button_Height 30.0f // 高
- //#define Button_Width (SCREEN_WIDTH-60)/4 // 宽
- #define Button_Width 60 // 宽
- @interface ReleaseresultsViewController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate,UITextFieldDelegate>{
- UITableView *newtableView;
- NSMutableArray *dataArray;
- NSMutableArray *titledataArray;//标题数组
- NSMutableArray *updateArr;
- NSString *descriptionStr;//成果描述 接收字符串
- NSString *resultsTitleStr;//成果标题 接收字符
- UIButton *updatefrequencybtn;//更新频率
- BOOL isseemore;//查看更多
- NSString *technicaltypeStr;
- NSString *technicaltypeTag;
- }
- @end
- @implementation ReleaseresultsViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"发布成果"];
- [self dataInitialization];
- [self Networkrequest];
- [self loadsView];
- // Do any additional setup after loading the view.
- }
- - (void)dataInitialization {
- isseemore = YES;
- dataArray = NewMutableArrayInit;
- titledataArray = [NSMutableArray arrayWithObjects:@"成果描述",@"成果标题",@"技术类型",@"其他",@"成果配图", nil];
- NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
- updateArr = [NSMutableArray arrayWithArray:arr];
- }
- - (void)Networkrequest {
-
- }
- #pragma mark ----加载界面
- - (void)loadsView{
- [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]];
- newtableView.separatorStyle = NO;
- }
- #pragma mark-------------------------UITableView------------------------------------
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 5;
- }
- //返回每段行数
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (section == 0||section == 1||section == 2) {
- return 1;
- }else if (section == 3){
- return 4;
- }
- return 3;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- static NSString *Cell = @"Cell";
- static NSString *Cell1 = @"Cell1";
- static NSString *Cell2 = @"Cell2";
- if (indexPath.section == 0) {
- ResultsdescriptionCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[ResultsdescriptionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- // [cell assignment:dataArray[indexPath.row]];
- cell.backgroundColor = NewLineGrayColor;
- cell.textview.delegate = self;
- return cell;
- }else if (indexPath.section == 1){
- ResultsTitleCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1];
- if (cell == nil) {
- cell = [[ResultsTitleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.backgroundColor = NewLineGrayColor;
- [cell.textfield addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
- return cell;
- }else if (indexPath.section == 2){
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1];
- if (cell == nil) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1];
-
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.backgroundColor = NewLineGrayColor;
- if (isseemore) {
- NSLog(@"更多1");
- NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
- [updateArr removeAllObjects];
- updateArr = [NSMutableArray arrayWithArray:arr];
- }else{
- NSLog(@"更多2");
- NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
- [updateArr removeAllObjects];
- updateArr = [NSMutableArray arrayWithArray:arr];
- }
- UIView *view = [[UIView alloc] init];
- CGFloat page = updateArr.count/4;
- view.frame = CGRectMake(0, 0, SCREEN_WIDTH, page * (Button_Height + Height_Space)+10);
- view.backgroundColor = NewLineGrayColor;
- [cell.contentView addSubview:view];
- for (int i = 0; i<updateArr.count; i++) {
- NSInteger num = 4;//每排4个
- NSInteger index = i % num;//每排4个
- NSInteger page = i / num;//
- UIButton *button = [UIButton new];
- if ([technicaltypeTag isEqualToString:[NSString stringWithFormat:@"%d",i]]) {
- [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [button setTitle:updateArr[i] forState:UIControlStateNormal];
- [button setBackgroundColor:NewButtonColor];
- ViewBorderRadius(button, 10, 0.6, NewButtonColor);
- }else{
- [button setTitle:updateArr[i] forState:UIControlStateNormal];
- [button setTitleColor:NewButtonColor forState:UIControlStateNormal];
- [button setBackgroundColor:NewWhiteColor];
- ViewBorderRadius(button, 10, .6, NewButtonColor);
- }
- button.tag = i;
- [button addTarget:self action:@selector(updatefrequencybtnclick:) forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(index * (fitScreenWidth(80) + fitScreenWidth(Width_Space)) + Start_X, page * (Button_Height + Height_Space)+10, fitScreenWidth(80), Button_Height);
- button.titleLabel.font = NewFont(fitScreenWidth(12));
- [view addSubview:button];
- }
- return cell;
- }else if (indexPath.section == 3){
- ReleaseresultsCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell2];
- if (cell == nil) {
- cell = [[ReleaseresultsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell2];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.backgroundColor = NewWhiteColor;
- if (indexPath.row == 0) {
- cell.line.hidden = NO;
- cell.title.text = @"所在地";
- }else{
- cell.line.hidden = YES;
- cell.title.text = @"行 业";
- }
- if (indexPath.row == 0) {
-
- }else{
- cell.textfield.placeholder = @"环保和资源";
- }
- // [cell assignment:dataArray[indexPath.row]];
- return cell;
- }
- return [[UITableViewCell alloc] init];
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 0) {
- return fitScreenWidth(134);
- }else if (indexPath.section == 1){
- return fitScreenWidth(64);
- }else if (indexPath.section == 2){
- if (isseemore) {
- NSLog(@"更多1");
- NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
- [updateArr removeAllObjects];
- updateArr = [NSMutableArray arrayWithArray:arr];
- CGFloat page = updateArr.count/4;
- return page * (Button_Height + Height_Space)+10;
- }else{
- NSLog(@"更多2");
- NSArray *arr = @[@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利",@"专利专利"];
- [updateArr removeAllObjects];
- updateArr = [NSMutableArray arrayWithArray:arr];
- CGFloat page = updateArr.count/4;
- return page * (Button_Height + Height_Space)+10;
- }
- }else if (indexPath.section == 3){
- if (indexPath.row == 0||indexPath.row == 1) {
- return 10+fitScreenWidth(44)+5;
- }
- return 10;
- }
- return fitScreenWidth(44);
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- }
- // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return fitScreenWidth(44)+10;
- }
- return fitScreenWidth(44);
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- static NSString * identy = @"head";
- UITableViewHeaderFooterView * hf = [tableView dequeueReusableHeaderFooterViewWithIdentifier:identy];
- NSLog(@"%li",section);
- hf = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:identy];
- UIView * view = [[UIView alloc]init];
- view.backgroundColor = [UIColor whiteColor];
- if (section == 0) {
- view.frame = CGRectMake(0, 10, SCREEN_WIDTH, fitScreenWidth(44));
- }else{
- view.frame = CGRectMake(0, 0, SCREEN_WIDTH, fitScreenWidth(44));
- }
- [hf addSubview:view];
-
- UILabel *line = [UILabel new];
- line.backgroundColor = NewButtonColor;
- ViewRadius(line, 1);
- [view addSubview:line];
-
- line.sd_layout
- .leftSpaceToView(view, 15)
- .centerYEqualToView(view)
- .heightIs(fitScreenWidth(18))
- .widthIs(3);
-
- UILabel *title = [UILabel new];
- [title setText:titledataArray[section]];
- [title setFont:NewFont(fitScreenWidth(13))];
- [title setSingleLineAutoResizeWithMaxWidth:0];
- [view addSubview:title];
-
- title.sd_layout
- .leftSpaceToView(line, 7)
- .heightIs(fitScreenWidth(44))
- .topEqualToView(view)
- .centerYEqualToView(view);
-
- UIButton *seemore = [UIButton new];
- [seemore setBackgroundColor:NewRedColor];
- [seemore setImage:[UIImage imageNamed:@"发现-科技成果"] forState:UIControlStateNormal];
- [seemore setImage:[UIImage imageNamed:@"发现-科技需求"] forState:UIControlStateSelected];
- NewTouchUpInside(seemore, seemoreclick:);
- [view addSubview:seemore];
-
- seemore.sd_layout
- .rightSpaceToView(view, 15)
- .heightIs(30)
- .widthIs(50)
- .centerYEqualToView(view);
- if (section == 2) {
- seemore.hidden = NO;
- }else{
- seemore.hidden = YES;
- }
- return hf;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- #pragma mark - UITextView获得焦点之后,并且已经是第一响应者
- -(void)textViewDidBeginEditing:(UITextView *)textView
- {
- // NSLog(@"UITextView获得焦点之后,并且已经是第一响应者");
- if ([textView.text isEqualToString:@"请描述您的技术成果~"]) {
- textView.text = @"";
- textView.textColor = NewGrayColor;
- }
- }
- #pragma mark - UITextView失去焦点之后
- -(void)textViewDidEndEditing:(UITextView *)textView
- {
- //NSLog(@"UITextView失去焦点");
- if ([textView.text isEqualToString:@""] || textView.text.length == 0) {
- textView.text = @"请描述您的技术成果~";
- textView.textColor = NewRGBColor(199, 199, 205, 1);
- }
- }
- #pragma mark - 详细地址限制字数
- -(void)textViewDidChangeSelection:(UITextView *)textView
- {
- if(textView.text.length > 500){
- textView.text = [textView.text substringWithRange:NSMakeRange(0,500)];
- }
- if (textView.text.length > 0) {
- NSLog(@"textView.text:%@",textView.text);
- if ([textView.text isEqualToString:@"请描述您的技术成果~"]) {
- descriptionStr = @"";
- }else{
- descriptionStr = nil;
- descriptionStr = textView.text;
- }
- }
- }
- #pragma mark - TextField作字符输入限制
- - (void)textFieldEditingChanged:(UITextField *)textField
- {
- if ([textField.text length]>50) {
- UITextRange *markedRange = [textField markedTextRange];
- if (markedRange) {
- return;
- }
- NSRange range = [textField.text rangeOfComposedCharacterSequenceAtIndex:50];
- textField.text = [textField.text substringToIndex:range.location];
- [self.view makeToast:@"标题最多输入50个字哦~" duration:1.5 position:CSToastPositionCenter];
- }
- resultsTitleStr = textField.text;
-
- NSLog(@"%@",resultsTitleStr);
- }
- - (void)seemoreclick:(UIButton *)sender {
- NSLog(@"点击查看更多");
- sender.selected = !sender.selected;
- if (!sender.selected) {
- isseemore = YES;
- }else{
- isseemore = NO;
- }
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
- [newtableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
- // updatefrequencybtn = nil;
- }
- - (void)updatefrequencybtnclick:(UIButton *)sender {
- if(updatefrequencybtn == sender) {
- //针对最后一个按钮创建
- NSLog(@"1111");
- } else{
- //本次点击的按钮设为白色
- [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [sender setBackgroundColor:NewButtonColor];
- ViewBorderRadius(sender, 10, 0.6, NewButtonColor);
- //将上次点击过的按钮设为蓝色
- [updatefrequencybtn setTitleColor:NewButtonColor forState:UIControlStateNormal];
- [updatefrequencybtn setBackgroundColor:NewWhiteColor];
- ViewBorderRadius(updatefrequencybtn, 10, 0.6, NewButtonColor);
- }
- updatefrequencybtn = sender;
- technicaltypeTag = [NSString stringWithFormat:@"%ld",sender.tag];
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
- [newtableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
- NSLog(@"%@",technicaltypeStr);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|