CommonGridViewController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // OrderListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-7-7.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CommonGridViewController.h"
  9. #import "AppDelegate.h"
  10. #import "iSalesNetwork.h"
  11. //#import "OrderListCell.h"
  12. #import "CommonEditorViewController.h"
  13. //#import "PopupNavigationController.h"
  14. @interface CommonGridViewController ()
  15. @end
  16. @implementation CommonGridViewController
  17. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  18. {
  19. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  20. if (self) {
  21. // Custom initialization
  22. }
  23. return self;
  24. }
  25. - (void)onAddClick:(UIButton *)sender {
  26. CommonEditorViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CommonEditorViewController"];
  27. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  28. navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  29. [self presentViewController:navi animated:YES completion:^{
  30. NSLog(@"login.........");
  31. self.btop = false;
  32. // <#code#>
  33. }];
  34. }
  35. - (void)onSearch:(UIButton *)sender {
  36. CommonEditorViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CommonEditorViewController"];
  37. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  38. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  39. [self presentViewController:navi animated:YES completion:^{
  40. NSLog(@"login.........");
  41. self.btop = false;
  42. // <#code#>
  43. }];
  44. }
  45. -(void)viewDidDisappear:(BOOL)animated
  46. {
  47. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  48. [app.window removeGestureRecognizer:self.tapGesture];
  49. }
  50. - (void)viewDidLoad
  51. {
  52. [super viewDidLoad];
  53. // Do any additional setup after loading the view.
  54. UIBarButtonItem *addButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(onAddClick:)];
  55. UIBarButtonItem *searchButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(onSearch:)];
  56. // id aa = self.navigationItem;
  57. // self.navi_item.title = @"ttttt";
  58. // self.navigationItem.rightBarButtonItem = searchButton;
  59. self.navi_item.rightBarButtonItems=[NSArray arrayWithObjects:addButton,searchButton, nil];
  60. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handletapPressGesture:)];
  61. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  62. [app.window addGestureRecognizer:tapGesture];
  63. tapGesture.delegate = self;
  64. self.btop = true;
  65. self.tapGesture = tapGesture;
  66. self.grid.fullrowselect = true;
  67. self.grid.enableTap = self.enableTap;
  68. self.grid.enableLongPress = self.enableLongPress;
  69. self.grid.griddelegate = self;
  70. }
  71. - (void)didReceiveMemoryWarning
  72. {
  73. [super didReceiveMemoryWarning];
  74. // Dispose of any resources that can be recreated.
  75. }
  76. -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  77. {
  78. if(!self.btop)
  79. return NO;
  80. if ([NSStringFromClass([touch.view class]) isEqualToString:@"SimpleGrid"]) {//如果当前是tableView
  81. //做自己想做的事
  82. return NO;
  83. }
  84. return YES;
  85. }
  86. -(void)handletapPressGesture:(UITapGestureRecognizer*)sender{
  87. CGPoint point = [sender locationInView:self.view];
  88. if (point.x<self.view.frame.origin.x || point.x >self.view.frame.origin.x+self.view.frame.size.width||point.y<self.view.frame.origin.y||point.y>self.view.frame.origin.y+self.view.frame.size.height) {
  89. [self dismissViewControllerAnimated:YES
  90. completion:^{
  91. //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
  92. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  93. [app.window removeGestureRecognizer:sender];
  94. }];
  95. }
  96. }
  97. #pragma mark - Longpress Menu
  98. - (void) showDetail:(UIMenuItem*) sender {
  99. CommonEditorViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CommonEditorViewController"];
  100. // orderinfoVC.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  101. // [self presentViewController:orderinfoVC animated:YES completion:^{
  102. //
  103. // NSLog(@"login.........");
  104. // // <#code#>
  105. // }];
  106. ////
  107. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  108. navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  109. [self presentViewController:navi animated:YES completion:^{
  110. NSLog(@"login.........");
  111. self.btop = false;
  112. // <#code#>
  113. }];
  114. // orderlistVC.delegate = self;
  115. }
  116. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  117. {
  118. if (action == @selector(showDetail:))
  119. return YES;//显示
  120. else
  121. return NO;//不显示
  122. }
  123. - (BOOL)canBecomeFirstResponder{
  124. return YES;
  125. }
  126. #pragma mark - SimpleGridDelegate
  127. - (void)Tap:(UIView *)view row:(long)x
  128. {
  129. }
  130. //- (void) LongPress:(UIView*)view row:(int) x column:(int) y;
  131. - (void) LongPress:(UIView*)view row:(long) x
  132. {
  133. DebugLog(@"!!!!!!!!!!!!!!!!!");
  134. NSDictionary *objrecord = [self.grid.data objectForKey:[NSString stringWithFormat:@"item_%ld",x]];
  135. self.orderID = [objrecord valueForKey:@"id"];
  136. [self becomeFirstResponder];
  137. UIMenuItem *detail = [[UIMenuItem alloc] initWithTitle:@"Open" action:@selector(showDetail:)];
  138. //detail.
  139. // [detail setValue:_id forKey:@"_id"];
  140. UIMenuController *menu = [UIMenuController sharedMenuController];
  141. [menu setMenuItems:[NSArray arrayWithObjects:detail, nil]];
  142. [menu setTargetRect:view.frame inView:view.superview];
  143. [menu setMenuVisible:YES animated:YES];
  144. }
  145. @end