2012-03-27 78 views
0

如果ViewController的視圖設置爲MyView哪裏在ViewController應UIGestureRecognizer設置?

enter image description here

enter image description here

和ViewController保持一個指向它的視圖(通過故事板設置)

@property (weak, nonatomic) IBOutlet MyView *v; 

凡在ViewController,應該發生以下情況嗎?

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] 
      initWithTarget:v action:@selector(pan:)]; 
[v addGestureRecognizer: panGesture]; 
+0

。有v已經創建。 – beryllium 2012-03-27 18:55:25

+0

爲什麼不在故事板中拖動手勢識別器? – dasdom 2012-03-27 19:01:48

+0

@dasdom我發現代碼更清晰 – JAM 2012-03-27 19:20:42

回答

1

viewDidLoad是這種初始化的好地方,因爲視圖層次將一直在該點加載到內存中,無論是從故事板或筆尖加載,或編程方式創建。

0

既然看起來您使用的是XIB文件,您的視圖viewDidLoad是正確的。 `viewDidLoad`中的