2012-09-11 18 views
3

我有一個名爲SubViewController.h的小型320x144視圖控制器,其中有一個UITableView,其中包含3個單元格的單元格。我已經使tableView不可滾動,並且還通過CALayer的優雅將一些陰影效果放在tableView後面。在使用UIPanGestureRecognizer拖動後,必須點擊兩次以選擇UITableViewCell

在另一個名爲MainViewController.m的視圖控制器中,我添加了SubViewController.h作爲子視圖MainViewController。使用UIPanGestureRecognizer我已經成功地能夠拖動SubViewContoller任何地方我想要的。

我使這個子視圖可見與UIBarButtonItem。在子視圖的tableView中選擇一個單元格後,我使用某些動畫從主視圖中消失。

一切工作正常。

但是,當我拖動子視圖,然後嘗試選擇一個單元我必須點擊兩次單元格。在第一次點擊時,除了單元格變爲藍色之外,沒有任何實際發生(就像在桌面視圖中選擇單元格時正常發生的那樣),但不會隱藏。如果我再次點擊,則會隱藏。

沒有拖動子視圖,我可以選擇一個單一的觸摸單元格,也視圖隱藏。

我已經編寫了子視圖的didSelectRowAtIndexPath:方法隱藏子視圖的代碼。並且我已經檢查過這種方法,當我第一次選擇拖動子視圖後不會調用這個方法。在第二次敲擊或觸摸它時會被調用。再次,如果用戶再次移動子視圖,則會出現同樣的問題。

當然,子視圖的某些屬性在拖動後發生了變化,我無法弄清楚。

回答

0
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 

    NSUInteger tapCount = [touch tapCount]; 

    switch (tapCount) { 
     case 1: 
      [self performSelector:@selector(singleTapMethod) withObject:nil afterDelay:.4]; 
      break; 
     case 2: 
      [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil]; 
      [self performSelector:@selector(doubleTapMethod) withObject:nil afterDelay:.4]; 
      break; 
. . . 
} 
+0

這不是什麼我期望。我相信我必須在UIGestureRecocgnizerStateEnded時寫點東西。 –

0

首先當u要顯示你的子視圖,這是對你的UIBarButtonItem的點擊:

-(IBAction)buttonClick 
{ 
     //setup ur view dynamically as you like// 
     PSview=[[UIView alloc]initWithFrame:CGRectMake(5, 5, 310,450)]; 
     PSview.backgroundColor=[UIColor blackColor]; 
     PSview.alpha=0.8; 
     [PSview.layer setBorderColor: [[UIColor whiteColor] CGColor]]; 
     [PSview.layer setBorderWidth: 3.0]; 


    PSview.contentMode=UIViewContentModeScaleAspectFill; 
    PSview.clipsToBounds=YES; 
    [PSview.layer setBorderColor: [[UIColor whiteColor] CGColor]]; 
    [PSview.layer setBorderWidth: 3.0]; 

    [PSview addSubview:subView]; 
    [self.view addSubview:PSview]; 

}

再後來:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
//since there are two tables in one view, you can differentiate them using if() 
    if(tableView==subView) 
     { 
      // ...ur code . .. 
      // write your code what needs to happen when you click a row of your subView. 
      [PSview removeFromSuperview]; 
     } 
    if(tableView==mainView) 
     { 
     // write your code , what happens when user clicks row of the main table 
     } 
    } 
+0

你能否詳細說明你的看法? –

+0

感謝您的回答 –

+0

是的,我知道那..但無法解決我的問題 –

相關問題