iphone @selector帶參數問題


今天是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");
  }
}

以上是我的心得。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM