CommonGridViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. DebugLog(@"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. DebugLog(@"login.........");
  41. self.btop = false;
  42. // <#code#>
  43. }];
  44. }
  45. -(void)viewDidDisappear:(BOOL)animated
  46. {
  47. [super viewDidDisappear:animated];
  48. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  49. [app.window removeGestureRecognizer:self.tapGesture];
  50. }
  51. - (void)viewDidLoad
  52. {
  53. [super viewDidLoad];
  54. // Do any additional setup after loading the view.
  55. UIBarButtonItem *addButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(onAddClick:)];
  56. UIBarButtonItem *searchButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(onSearch:)];
  57. // id aa = self.navigationItem;
  58. // self.navi_item.title = @"ttttt";
  59. // self.navigationItem.rightBarButtonItem = searchButton;
  60. self.navi_item.rightBarButtonItems=[NSArray arrayWithObjects:addButton,searchButton, nil];
  61. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handletapPressGesture:)];
  62. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  63. [app.window addGestureRecognizer:tapGesture];
  64. tapGesture.delegate = self;
  65. self.btop = true;
  66. self.tapGesture = tapGesture;
  67. self.grid.fullrowselect = true;
  68. self.grid.enableTap = self.enableTap;
  69. self.grid.enableLongPress = self.enableLongPress;
  70. self.grid.griddelegate = self;
  71. }
  72. - (void)didReceiveMemoryWarning
  73. {
  74. [super didReceiveMemoryWarning];
  75. // Dispose of any resources that can be recreated.
  76. }
  77. -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  78. {
  79. if(!self.btop)
  80. return NO;
  81. if ([NSStringFromClass([touch.view class]) isEqualToString:@"SimpleGrid"]) {//如果当前是tableView
  82. //做自己想做的事
  83. return NO;
  84. }
  85. return YES;
  86. }
  87. -(void)handletapPressGesture:(UITapGestureRecognizer*)sender{
  88. CGPoint point = [sender locationInView:self.view];
  89. 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) {
  90. [self dismissViewControllerAnimated:YES
  91. completion:^{
  92. //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
  93. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  94. [app.window removeGestureRecognizer:sender];
  95. }];
  96. }
  97. }
  98. #pragma mark - Longpress Menu
  99. - (void) showDetail:(UIMenuItem*) sender {
  100. CommonEditorViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CommonEditorViewController"];
  101. // orderinfoVC.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  102. // [self presentViewController:orderinfoVC animated:YES completion:^{
  103. //
  104. // DebugLog(@"login.........");
  105. // // <#code#>
  106. // }];
  107. ////
  108. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  109. navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  110. [self presentViewController:navi animated:YES completion:^{
  111. DebugLog(@"login.........");
  112. self.btop = false;
  113. // <#code#>
  114. }];
  115. // orderlistVC.delegate = self;
  116. }
  117. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  118. {
  119. if (action == @selector(showDetail:))
  120. return YES;//显示
  121. else
  122. return NO;//不显示
  123. }
  124. - (BOOL)canBecomeFirstResponder{
  125. return YES;
  126. }
  127. #pragma mark - SimpleGridDelegate
  128. - (void)Tap:(UIView *)view row:(long)x
  129. {
  130. }
  131. //- (void) LongPress:(UIView*)view row:(int) x column:(int) y;
  132. - (void) LongPress:(UIView*)view row:(long) x
  133. {
  134. DebugLog(@"!!!!!!!!!!!!!!!!!");
  135. NSDictionary *objrecord = [self.grid.data objectForKey:[NSString stringWithFormat:@"item_%ld",x]];
  136. self.orderID = [objrecord valueForKey:@"id"];
  137. [self becomeFirstResponder];
  138. UIMenuItem *detail = [[UIMenuItem alloc] initWithTitle:@"Open" action:@selector(showDetail:)];
  139. //detail.
  140. // [detail setValue:_id forKey:@"_id"];
  141. UIMenuController *menu = [UIMenuController sharedMenuController];
  142. [menu setMenuItems:[NSArray arrayWithObjects:detail, nil]];
  143. [menu setTargetRect:view.frame inView:view.superview];
  144. [menu setMenuVisible:YES animated:YES];
  145. }
  146. @end