2011-05-23 42 views
1

我想給一個NSTimer參數。 timertocallguest是在.h中製作的NSTimer;NSTimer參數NSIndexPath

timertocallguest=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(gettheguestyouaskedforTOTURNON) userInfo:nil repeats:YES]; 

我該如何傳遞參數與選擇器? 在一些選擇器中,我可以在它後面添加withObject來給它提供參數..但是我不能在這裏做,我只是想給一個NSIndexPath帶上我調用的函數。

可以annyone幫助我嗎? Ty已經,

+0

[將參數傳遞給NSTimer所調用的方法](http://stackoverflow.com/questions/4011297/passing-parameters-to-the-method-called-by-a-nstimer) – 2011-05-23 07:36:20

回答

2

您的電話在選擇器名稱後缺少冒號。它應該這樣寫:

timertocallguest=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(gettheguestyouaskedforTOTURNON:) userInfo:nil repeats:YES]; 

如果Xcode中雖然提出沒有冒號的選擇,確保你想實際調用該方法採用(類型idNSIndexPath*的)參數。響應

編輯評論:

的對象(在這種情況下myObject的)需要傳遞中作爲用戶信息,例如:

timertocallguest=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(gettheguestyouaskedforTOTURNON:) userInfo:myOject repeats:YES]; 
+0

I能夠在沒有collon的情況下做出選擇,並且它正在工作。所以這是正確的方式? - (無效)gettheguestyouaskedforTOTURNON:(NSIndexPath *)therow與的NSTimer \t \t timertocallguest = [的NSTimer scheduledTimerWithTimeInterval:1 \t \t \t \t \t \t \t \t \t \t目標:自 \t \t \t \t \t \t \t \t \t \t \t \t \t \t選擇器:@selector(gettheguestyouaskedforTOTURNON:selectedIn dexPath) \t \t \t \t \t \t \t \t \t USERINFO:無 \t \t \t \t \t \t \t \t \t重複:YES]; – Oblieapps 2011-05-23 07:43:46

+0

不,請參閱我的編輯! – Toastor 2011-05-23 07:53:15

+0

嗯我現在得到了這個,但我不斷得到一個NSFCTimer錯誤.. - (void)gettheguestyouaskedforTOTURNON:(NSIndexPath *)therow {; timertocallguest = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(gettheguestyouaskedforTOTURNON :) userInfo:SelectedIndexPath repeatats:YES]; SelectedIndexPath是一個NSIndexPath對象,我使用獲取行的索引。 – Oblieapps 2011-05-23 08:09:08

0

我有一個類似的問題,當我從 - (UITableViewCell *)tableView:(UITableView *)調用一個方法tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath使用NSTimer。