| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- //
- // ModelHonorViewController.m
- // model
- //
- // Created by liufei on 2018/7/25.
- // Copyright © 2018年 Mine. All rights reserved.
- //
- #import "ModelHonorViewController.h"
- #import "HonorTableViewCell.h"
- @interface ModelHonorViewController () <UITableViewDelegate, UITableViewDataSource, UITextViewDelegate>
- @property(nonatomic, strong) UITableView *listView;
- @property(nonatomic, strong) NSMutableArray *dataSource;
- @end
- @implementation ModelHonorViewController
- - (NSMutableArray *)dataSource {
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- self.title = @"我的荣誉";
- self.navigationController.navigationBar.tintColor = RGBValueColor(0x333333, 1);
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(addHonor)];
- [self getHonorData];
- }
- - (void)getHonorData {
- [YanCNetWorkManager requestGETWithURLStr:Url_getModelHonor(PublicUrl)
- parameters:@{@"ModelPK": [ModelUser user].modelpk}
- finish:^(id dataDic) {
- if ([dataDic[@"msg"] isEqualToString:@"success"]) {
- NSArray *array = dataDic[@"data"];
- for (int i = 0; i < array.count; i++) {
- NSDictionary *dic = array[i];
- [self.dataSource addObject:dic[@"honor"]];
- }
- [self configUI];
- }
- }
- enError:^(NSError *error) {
- }];
- }
- - (void)configUI {
- self.listView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
- self.listView.delegate = self;
- self.listView.dataSource = self;
- self.listView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- self.listView.rowHeight = 143.f;
- self.listView.tableFooterView = [self footView];
- [self.listView registerNib:[UINib nibWithNibName:@"HonorTableViewCell" bundle:nil] forCellReuseIdentifier:NSStringFromClass([HonorTableViewCell class])];
- [self.view addSubview:self.listView];
- }
- - (void)addHonor {
- [self.dataSource addObject:@""];
- [self.listView reloadData];
- }
- - (void)handleSave {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- for (NSString *str in self.dataSource) {
- if (str.length > 0) {
- NSDictionary *dicc = @{@"honor": str};
- [arr addObject:dicc];
- }
- }
- NSString *jsonStr = [arr mj_JSONString];
- NSDictionary *dic = @{@"ModelPK": [ModelUser user].modelpk, @"Honor": jsonStr};
- [YanCNetWorkManager requestPostWithURLStr:Url_addModelHonor(PublicUrl) parameters:dic finish:^(id dataDic) {
- if ([[dataDic objectForKey:@"msg"] isEqualToString:@"success"]) {
- [MBProgressHUD showSuccess:@"保存成功"];
- [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(backClick) userInfo:nil repeats:NO];
- } else {
- [MBProgressHUD showSuccess:@"保存失败"];
- }
- } enError:^(NSError *error) {
- }];
- }
- - (void)backClick {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (UIView *)footView {
- UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 120)];
- UIButton *saveBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 40, ScreenWidth - 40, 48)];
- saveBtn.layer.cornerRadius = 24.f;
- saveBtn.layer.masksToBounds = YES;
- [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
- [saveBtn addTarget:self action:@selector(handleSave) forControlEvents:UIControlEventTouchUpInside];
- [saveBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal];
- [footView addSubview:saveBtn];
- return footView;
- }
- #pragma mark -
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return self.dataSource.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellid = @"HonorTableViewCell";
- HonorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
- if (!cell) {
- cell = [[HonorTableViewCell alloc] init];
- }
- // HonorTableViewCell *cell = [[HonorTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HonorTableViewCell"];
- if (self.dataSource.count > 0) {
- cell.honorTextView.text = self.dataSource[indexPath.section];
- }
- cell.numberLabel.text = [NSString stringWithFormat:@"%zd", cell.honorTextView.text.length];
- cell.honorTextView.tag = indexPath.section;
- cell.honorTextView.delegate = self;
- return cell;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
- headView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- if (section == 0) {
- UILabel *headLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, ScreenWidth - 40, 40)];
- headLabel.font = [UIFont systemFontOfSize:14];
- headLabel.textColor = RGBValueColor(0x666666, 1);
- headLabel.text = @"我的荣誉";
- [headView addSubview:headLabel];
- }
- return headView;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return section == 0 ? 40.f : 10.f;
- }
- - (void)textViewDidEndEditing:(UITextView *)textView {
- [self.listView reloadData];
- }
- - (void)textViewDidChange:(UITextView *)textView {
- [self.dataSource replaceObjectAtIndex:textView.tag withObject:textView.text];
- }
- - (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
|