2016-03-12 24 views
-1

當我們點擊視圖時如何解除tableview?我使用touch開始method.but它不工作?當觸及tableview.How如何解除tableView?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
NSLog(@"touches began"); 
UITouch *touch = [touches anyObject]; 
if(touch.view!=myTableView){ 
    myTableview.hidden = YES; 
} 
} 

如何禁用表,當我們點擊view.i我有三個tableviews?

回答

0

試試這個

viewDidLoad中

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelGesture:)]; 
     [self.view addGestureRecognizer:tap]; 

ActionMethod

- (void) handelGesture:(UITapGestureRecognizer*)sender 
    { 
     myTableview.hidden = YES; 
    } 

希望這有助於。

+0

它的工作如果有幫助你請投了 謝謝:) –

-1

請檢查驗證碼,如果你修改了你的要求,謝謝

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
     NSArray *subviews = [self.view subviews]; 
     for (id objects in subviews) { 
      if ([objects isKindOfClass:[UITextField class]]) { 
       UITextField *theTextField = objects; 
       if ([objects isFirstResponder]) { 
        [theTextField resignFirstResponder]; 
       } 
      } 
     } 
    }