2012-06-13 75 views
1

我有一堆tapGestureRecognizer鏈接到它們的按鈕,並且這會執行相應的操作。觸摸不顯示高亮,tapGestureRecognizer

由於我有這麼多的按鈕,我不想通過IBAction手動鏈接它們。

現在我收到的問題是,它沒有立即顯示showsTouchOnHighlight。我不知道如何解決這個問題,這裏是我使用的代碼:

- (void)tapPress:(UITapGestureRecognizer *)sender { 

    UIButton *resultButton = (UIButton *)sender.view; 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" 
                 bundle:[NSBundle bundleForClass:[self class]]]; 
    infoView *infoViewController = [storyboard instantiateViewControllerWithIdentifier:resultButton.currentTitle]; 
    infoViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    [self presentViewController:infoViewController 
         animated:YES 
        completion:nil]; 
} 
+0

我不明白。爲什麼使用輕擊手勢識別器而不是僅使用按鈕的touchUpInside事件? –

+0

,因爲我有38個按鈕,我可以輕鬆創建手勢識別器,而不是通過界面生成器鏈接所有按鈕。 –

+0

您是否在代碼中創建手勢識別器?您可以使用'addTarget:action:forControlEvents:'消息在代碼中設置按鈕的目標和操作。 [Documentation](http://developer.apple.com/library/ios/documentation/uikit/reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instm/UIControl/addTarget:action:forControlEvents :) –

回答

2

而是用自來水手勢識別的,請嘗試使用addTarget:action:forControlEvents:方法來設置每個按鈕的目標和行動。這應該可以節省連接筆尖中每個按鈕的工作量。