// // AddExtDocumentViewController.m // Granite Expo eSign // // Created by Ray on 01/03/2017. // Copyright © 2017 United Software Applications, Inc. All rights reserved. // #import "AddExtDocumentViewController.h" #import "MenuViewController.h" #import "RAMenu.h" #import "ImageUtils.h" #import "PDFViewController.h" @interface AddExtDocumentViewController () @end @implementation AddExtDocumentViewController - (void)viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; self.arr_documents = [[NSMutableArray alloc]init]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)onScanClicked:(id)sender { } - (IBAction)onAddImageClicked:(id)sender { __weak typeof(self) weakself = self; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add Image From" message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text = self.save_name; // // // }]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Album" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSUInteger sourceType=UIImagePickerControllerSourceTypePhotoLibrary; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = weakself; imagePickerController.allowsEditing = YES; imagePickerController.sourceType = sourceType; [self presentViewController:imagePickerController animated:YES completion:^{}]; }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Take a photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { return; } NSUInteger sourceType=UIImagePickerControllerSourceTypeCamera; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = weakself; imagePickerController.allowsEditing = YES; imagePickerController.sourceType = sourceType; [self presentViewController:imagePickerController animated:YES completion:^{}]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; [alertControl addAction:actionOne]; [alertControl addAction:action2]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; return; NSMutableArray* menuItem = [NSArray arrayWithObjects:@"aaa",@"bbb",nil]; UIView* v= sender; RAMenu * menu= [[RAMenu alloc]initWithFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y, 120, 88)]; // menu.backgroundColor= [UIColor whiteColor]; menu.arr_menuItems = menuItem; [self.view addSubview:menu]; menu.hidden = false; return; MenuViewController *menuVC = [[MenuViewController alloc]init]; menuVC.arr_menuItems = [menuItem mutableCopy]; // // menuVC.title=@"menu"; // signatureVC.signatureData = self.signatureData; // // signatureVC.blk_Add = ^() // { // // __block UIImage* signimg=nil; // SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"]; // // vc.onReturnImg = ^(UIImage* img) // { // // // signimg = img; // // // if(signimg!=nil) // // [PDFUtils addSignature:signimg to:self.signatureData]; // // // // // }; // // // orderinfoVC.url_type = URL_REMOTE; // // orderinfoVC.request_url=URL_CARTDELIVERY; // // // // orderinfoVC.params = params; // // // // orderinfoVC.delegate=self; // // // // if(checked.count==count) // // { // // orderinfoVC.have_tail = true // // } // // [self.navigationController pushViewController:vc animated:true]; // // // // }; UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:menuVC]; navi.modalPresentationStyle=UIModalPresentationPopover; UIPopoverPresentationController* popPc = navi.popoverPresentationController; popPc.permittedArrowDirections = UIPopoverArrowDirectionUp; popPc.sourceView = sender; popPc.delegate = nil; [self presentViewController:navi animated:true completion:nil]; } - (IBAction)onAddFileClicked:(id)sender { } - (IBAction)onUploadClicked:(id)sender { } #pragma mark - Table view data source - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { return 44; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 44; //} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.arr_documents.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"ADTableViewCell"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSDictionary * item_json = self.arr_documents[indexPath.row]; NSString* type = item_json[@"type"]; NSString* file_name = item_json[@"file_name"]; NSString* upload_date = item_json[@"upload_date"]; NSString* url = item_json[@"url"]; if([type isEqualToString:@"file"]) cell.imageView.image = [UIImage imageNamed:@"file_icon"]; else cell.imageView.image = [UIImage imageNamed:@"picture_icon"]; cell.textLabel.text = file_name; cell.detailTextLabel.text = upload_date; return cell; } #pragma mark tableview delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary * item_json = self.arr_documents[indexPath.row]; NSString* url = item_json[@"url"]; bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"]; PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"]; ViewController.url = url; ViewController.canSave = false; ViewController.isLocalfile=isLocalFile; ViewController.defaultStyle = true; ViewController.hidenavi = false; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ; navi.modalPresentationStyle = UIModalPresentationFullScreen;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ }]; } #pragma mark - imagePicker delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ // self.dirty = true; /*-------------------------------相机拍照--------------------------------------*/ if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage]; image=[ImageUtils img_compress:image kbsize:512]; NSString *path = NSTemporaryDirectory(); NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]]; [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES]; NSMutableDictionary* item = [[NSMutableDictionary alloc]init]; item[@"type"]=@"image"; item[@"url"]= filePath; item[@"file_name"]= [filePath lastPathComponent]; [self.arr_documents addObject:item]; [self.tableView reloadData]; [picker dismissViewControllerAnimated:YES completion:^{ }]; } else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { /** * UIImagePickerControllerEditedImage 取得的是被编辑过的图片,需要allowsEditing设置为YES * UIImagePickerControllerOriginalImage 取得的是相册中原始图片 */ UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage]; image=[ImageUtils img_compress:image kbsize:512]; NSString *path = NSTemporaryDirectory(); NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]]; [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES]; NSMutableDictionary* item = [[NSMutableDictionary alloc]init]; item[@"type"]=@"image"; item[@"url"]= filePath; item[@"file_name"]= [filePath lastPathComponent]; [self.arr_documents addObject:item]; [self.tableView reloadData]; [picker dismissViewControllerAnimated:YES completion:nil]; } } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [picker dismissViewControllerAnimated:YES completion:nil]; // [picker presentViewController:cameraPicker animated:YES completion:nil]; // DebugLog(@"%s",__FUNCTION__); } /* #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