2012-07-30 45 views
0

我已經手動創建了一個對象(文件 - >新建 - >新建類 - > UITableViewCell)並添加了.xib。 創建細胞有多個標籤,看到的景象created Cell如何爲手動創建的對象添加gestureRecognizer?

後,我用這個對象在其他類

myCell * showHere; 
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"myCell" owner:self options:nil]; 
showHere = [nib objectAtIndex:0]; 

我怎樣才能在這個小區添加gestureRecognizer爲的UILabel?

我已經試過這樣:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
              initWithTarget:self 
              action:@selector(handleLongPress:)]; 
longPress.minimumPressDuration = 1.0; 
[showHere.monday addGestureRecognizer:longPress]; 

-(void)handleLongPress:(UILongPressGestureRecognizer*)recognizer { 
NSLog(@"label has pressed"); 

}

我需要通過按單個標籤上抓捕行動。可能嗎? 對不起,我的英文。

回答

1

只需添加YourLabel.userinteractionEnabled = YES

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 1.0;

爲了使觸摸到你的標籤

好運

+0

不,不'噸的工作..也許我錯了水木清華.. – Arthur 2012-07-30 14:02:54

+0

是細胞在didselectrow接收行動? – 2012-07-30 14:06:14

+0

是的。我甚至嘗試在單元類中創建識別器,但它不起作用... – Arthur 2012-07-31 08:04:48

相關問題