DepositAmountVC.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  2. // DepositAmountVC.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/7/24.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "DepositAmountVC.h"
  9. @interface DepositAmountVC ()
  10. @end
  11. @implementation DepositAmountVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. [self loadNavStyle];
  15. [self initUI];
  16. [self registerKeybordNotification];
  17. }
  18. -(void)loadNavStyle
  19. {
  20. //右边
  21. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  22. [btnAdd addTarget:self action:@selector(submitData)
  23. forControlEvents:UIControlEventTouchUpInside];
  24. btnAdd.frame = CGRectMake(0, 0,60,14);
  25. [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  26. btnAdd.titleLabel.font=[UIFont systemFontOfSize:16];
  27. [btnAdd setTitle:@"确定" forState:UIControlStateNormal];
  28. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  29. self.navigationItem.title=@"请选择";
  30. self.navigationItem.rightBarButtonItem = menubtnAdd;
  31. //返回
  32. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  33. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  34. forState:UIControlStateNormal];
  35. [button addTarget:self action:@selector(goBack)
  36. forControlEvents:UIControlEventTouchUpInside];
  37. button.frame = CGRectMake(0, 0, 15, 18);
  38. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  39. self.navigationItem.leftBarButtonItem = menuButton;
  40. if(_depositList!=nil&&_depositList.count>0){
  41. [_vTableView reloadData];
  42. }
  43. }
  44. -(void)initUI{
  45. _vTableView = [[UITableView alloc]
  46. initWithFrame:CGRectMake(0,
  47. 0,
  48. self.view.frame.size.width,
  49. self.view.frame.size.height)];
  50. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  51. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  52. _vTableView.backgroundColor = [UIColor whiteColor];
  53. _vTableView.delegate = self;
  54. _vTableView.dataSource=self;
  55. [self.view addSubview:_vTableView];
  56. }
  57. -(void)submitData{
  58. [self.view endEditing:YES];
  59. if([self.depositAmountDelegate respondsToSelector:@selector(callbackDepositAmount:)])
  60. {
  61. [self.depositAmountDelegate callbackDepositAmount:_depositList];
  62. }
  63. [self.navigationController popViewControllerAnimated:YES];
  64. }
  65. #pragma mark - tableView回调
  66. /**
  67. 单元格cell个数
  68. @param tableView <#tableView description#>
  69. @param section <#section description#>
  70. @return <#return value description#>
  71. */
  72. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  73. {
  74. return [_depositList count];
  75. }
  76. /**
  77. <#Description#>
  78. @param tableView <#tableView description#>
  79. @return <#return value description#>
  80. */
  81. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  82. return 1;
  83. }
  84. /**
  85. 高度
  86. @param tableView <#tableView description#>
  87. @param indexPath <#indexPath description#>
  88. @return <#return value description#>
  89. */
  90. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  91. return 92;
  92. }
  93. /**
  94. 每个单元格cell
  95. @param tableView <#tableView description#>
  96. @param indexPath <#indexPath description#>
  97. @return <#return value description#>
  98. */
  99. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  100. {
  101. static NSString *cellIdentifier = @"DepositAmountCell";
  102. DepositAmountCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  103. cell=[[DepositAmountCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  104. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  105. cell.position= indexPath.row;
  106. cell.cellDelegate=self;
  107. DepositAmountModel *depositModel = [_depositList objectAtIndex:indexPath.row];
  108. [cell parseDepositInfo:depositModel];
  109. return cell;
  110. }
  111. -(void)update:(int) position flag:(int) flag text:(NSString *) str{
  112. DepositAmountModel *model = [self.depositList objectAtIndex:position];
  113. if(flag == 1){
  114. model.feeItemSum = str;
  115. }else{
  116. model.remarks = str;
  117. }
  118. }
  119. // 键盘弹出改变tableview高度
  120. - (void)registerKeybordNotification {
  121. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  122. [notification removeObserver:self];
  123. [notification addObserver:self
  124. selector:@selector(showKeyboard:)
  125. name:UIKeyboardWillShowNotification
  126. object:nil];
  127. [notification addObserver:self
  128. selector:@selector(hideKeyboard:)
  129. name:UIKeyboardWillHideNotification
  130. object:nil];
  131. #ifdef __IPHONE_5_0
  132. // 5.0以上系统中文键盘高度与4.0系统不一样
  133. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  134. if (version >= 5.0) {
  135. [notification addObserver:self
  136. selector:@selector(showKeyboard:)
  137. name:UIKeyboardWillChangeFrameNotification
  138. object:nil];
  139. }
  140. #endif
  141. }
  142. - (void)showKeyboard:(NSNotification *)notification {
  143. NSDictionary *userInfo = [notification userInfo];
  144. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  145. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  146. CGFloat height = CGRectGetHeight(self.view.frame) - keyboardHeight;
  147. /* 使用动画效果,过度更加平滑 */
  148. [UIView beginAnimations:nil context:nil];
  149. [UIView setAnimationDuration:0.1];
  150. {
  151. CGRect rect = _vTableView.frame;
  152. rect.size.height = height;
  153. _vTableView.frame = rect;
  154. }
  155. [UIView commitAnimations];
  156. }
  157. - (void)hideKeyboard:(NSNotification *)notification {
  158. [UIView beginAnimations:nil context:nil];
  159. [UIView setAnimationDuration:0.1];
  160. {
  161. CGRect rect = _vTableView.frame;
  162. rect.size.height = CGRectGetHeight(self.view.frame) ;
  163. _vTableView.frame = rect;
  164. }
  165. [UIView commitAnimations];
  166. }
  167. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  168. if(scrollView.isDragging){
  169. [self.view endEditing:YES];
  170. }
  171. }
  172. - (void)goBack
  173. {
  174. [self.navigationController popViewControllerAnimated:YES];
  175. }
  176. - (void)didReceiveMemoryWarning {
  177. [super didReceiveMemoryWarning];
  178. }
  179. @end