2011-05-23 66 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。