今天是3月15號國際消費者權益日,現在就記錄下有關@selector的相關問題。
1 增加手勢:
UITapGestureRecognizer *oneFingerTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:
@selector(oneFingerTwoTaps:)] autorelease];
// Set required taps and number of touches
[oneFingerTwoTaps setNumberOfTapsRequired:2];
[oneFingerTwoTaps setNumberOfTouchesRequired:1];
// Add the gesture to the view
[[self view] addGestureRecognizer:oneFingerTwoTaps];
- (void)oneFingerTwoTaps:(UITapGestureRecognizer *)recognizer
{
UIView *viewT = [recognizer view];
if (viewT.tag==0)
{
NSLog(@"Action: One finger, two taps");
}
}
如果要帶一個參數的話,@selector(里頭必須有一個“:”);
如果是沒有帶參數的話,請看下面的代碼:同樣也是看紅色的部分。若@selector沒有帶參數的話,@selector(里頭不需要有“:”)
UITapGestureRecognizer *oneFingerTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:
@selector(oneFingerTwoTaps)] autorelease];
// Set required taps and number of touches
[oneFingerTwoTaps setNumberOfTapsRequired:2];
[oneFingerTwoTaps setNumberOfTouchesRequired:1];
// Add the gesture to the view
[[self view] addGestureRecognizer:oneFingerTwoTaps];
- (void)oneFingerTwoTaps
{
UIView *viewT = [recognizer view];
if (viewT.tag==0)
{
NSLog(@"Action: One finger, two taps");
}
}
以上是我的心得。