CheckSelectorViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // CheckSelectorViewController.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/22/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CheckSelectorViewController.h"
  9. @interface CheckSelectorViewController ()
  10. @end
  11. @implementation CheckSelectorViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. }
  16. - (void)didReceiveMemoryWarning {
  17. [super didReceiveMemoryWarning];
  18. // Dispose of any resources that can be recreated.
  19. }
  20. - (IBAction)OnOKClick:(id)sender {
  21. [self dismissViewControllerAnimated:false completion:^{
  22. if(self.blk_OK)
  23. self.blk_OK(self.checkedData);
  24. }];
  25. }
  26. - (IBAction)OnCancelClick:(id)sender {
  27. [self dismissViewControllerAnimated:false completion:nil];
  28. }
  29. /*
  30. #pragma mark - Navigation
  31. // In a storyboard-based application, you will often want to do a little preparation before navigation
  32. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  33. // Get the new view controller using [segue destinationViewController].
  34. // Pass the selected object to the new view controller.
  35. }
  36. */
  37. #pragma mark - Table view data source
  38. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  39. {
  40. return 44;
  41. }
  42. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  43. return @"";//[NSString stringWithFormat:@"Signature%ld",(long)section];
  44. }
  45. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  46. {
  47. return 1;
  48. }
  49. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  50. {
  51. return self.rowData.count;
  52. }
  53. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  54. {
  55. NSString *CellIdentifier = @"CheckItemCell";
  56. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  57. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  58. if (cell == nil) {
  59. if(self.show_detail)
  60. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  61. else
  62. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  63. }
  64. NSArray *item_arr = self.rowData[indexPath.row];
  65. cell.textLabel.text = item_arr[0][0];
  66. if(self.show_detail)
  67. {
  68. cell.detailTextLabel.text=item_arr[0][1];
  69. }
  70. if ([self.checkedData containsObject:[NSNumber numberWithInteger:indexPath.row]]) {
  71. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  72. } else {
  73. cell.accessoryType = UITableViewCellAccessoryNone;
  74. }
  75. return cell;
  76. }
  77. //- (UITableViewCellAccessoryType)tableView:(UITableView*)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath*)indexPath
  78. //{
  79. // if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
  80. // {
  81. // return UITableViewCellAccessoryCheckmark;
  82. // }
  83. // else
  84. // {
  85. // return UITableViewCellAccessoryNone;
  86. // }
  87. //}
  88. #pragma mark tableview delegate
  89. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
  92. // if (![tableView.delegate respondsToSelector:@selector(tableView:accessoryTypeForRowWithIndexPath:)]) {
  93. // cell.accessoryType = [self tableView:tableView accessoryTypeForRowWithIndexPath:indexPath];
  94. // }
  95. if(self.single_select)
  96. {
  97. [self.checkedData removeAllObjects];
  98. if(cell.accessoryType==UITableViewCellAccessoryNone)
  99. [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
  100. }
  101. else
  102. {
  103. if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
  104. {
  105. [self.checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
  106. }
  107. else
  108. {
  109. [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
  110. }
  111. }
  112. // 消除警告:tableView:accessoryTypeForRowWithIndexPath:
  113. if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
  114. {
  115. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  116. }
  117. else
  118. {
  119. cell.accessoryType = UITableViewCellAccessoryNone;
  120. }
  121. // cell.accessoryType=UITableViewCellAccessoryCheckmark;
  122. [tableView reloadData];
  123. // if(self.blk_Select)
  124. // {
  125. //
  126. // // SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath];
  127. //
  128. // NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
  129. //
  130. // // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
  131. //
  132. //
  133. // self.blk_Select(item_json[@"file"]);
  134. //
  135. // }
  136. //
  137. // [self dismissViewControllerAnimated:false completion:nil];
  138. }
  139. @end