// // CheckSelectorViewController.m // AntsContract // // Created by Ray on 12/22/16. // Copyright © 2016 United Software Applications, Inc. All rights reserved. // #import "CheckSelectorViewController.h" @interface CheckSelectorViewController () @end @implementation CheckSelectorViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)OnOKClick:(id)sender { [self dismissViewControllerAnimated:false completion:^{ if(self.blk_OK) self.blk_OK(self.checkedData); }]; } - (IBAction)OnCancelClick:(id)sender { [self dismissViewControllerAnimated:false completion:nil]; } /* #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. } */ #pragma mark - Table view data source - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { return 44; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return @"";//[NSString stringWithFormat:@"Signature%ld",(long)section]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.rowData.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"CheckItemCell"; // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { if(self.show_detail) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; else cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSArray *item_arr = self.rowData[indexPath.row]; cell.textLabel.text = item_arr[0][0]; if(self.show_detail) { cell.detailTextLabel.text=item_arr[0][1]; } if ([self.checkedData containsObject:[NSNumber numberWithInteger:indexPath.row]]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } //- (UITableViewCellAccessoryType)tableView:(UITableView*)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath*)indexPath //{ // if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]]) // { // return UITableViewCellAccessoryCheckmark; // } // else // { // return UITableViewCellAccessoryNone; // } //} #pragma mark tableview delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; // if (![tableView.delegate respondsToSelector:@selector(tableView:accessoryTypeForRowWithIndexPath:)]) { // cell.accessoryType = [self tableView:tableView accessoryTypeForRowWithIndexPath:indexPath]; // } if(self.single_select) { [self.checkedData removeAllObjects]; if(cell.accessoryType==UITableViewCellAccessoryNone) [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ]; } else { if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]]) { [self.checkedData removeObject:[NSNumber numberWithLong:indexPath.row]]; } else { [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ]; } } // 消除警告:tableView:accessoryTypeForRowWithIndexPath: if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } // cell.accessoryType=UITableViewCellAccessoryCheckmark; [tableView reloadData]; // if(self.blk_Select) // { // // // SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath]; // // NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]]; // // // UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]]; // // // self.blk_Select(item_json[@"file"]); // // } // // [self dismissViewControllerAnimated:false completion:nil]; } @end