索引路径作为参数

发布于 2024-11-09 17:52:36 字数 2000 浏览 0 评论 0原文

我有一个充满虚拟机的表,并且有 2 个数据类型 NSIndexPath 的变量,称为: selectedindexpath(用户点击的行)和 selectedindexpathFortheVMtoTurnOn(这样它就知道当虚拟机启动时要重新加载哪一行); 这都是在 .h 中作为 @paramters(retain) 制作的。

我有一个打开虚拟机的函数和一个使用 NSTimer 每 1 秒检查一次的函数,如果来宾最终打开,则它会重新加载 selectedindexpathFortheVMtoTurnOn 的行 我对关闭/重新启动做了同样的事情,但我遇到了一个问题..我无法请求超过 1 个虚拟机的操作..因为它正在用我发送操作的最后一行覆盖 selectedindexpathFortheVMtoTurnOn 值通过这样做,表响应很奇怪并且应用程序崩溃。 所以这就是为什么我想将indexpath.row值作为NSTimer的参数提供给每1秒检查一次的函数我尝试了一些方法但没有一个起作用..在我如何给出参数

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

和函数 的代码下面:

-(void)gettheguestyouaskedforTOTURNON:(NSIndexPath *)therow

当我尝试执行 NSLog("%d",therow.row); 时,它崩溃了......

并且使用 NSLog("%d",therow); > 我得到了完全不同的值selectedindexpathFortheVMtoTurnOn 它曾经有..

我做错了什么。?

抱歉,如果它是一面文字墙。但我确实需要解决这个问题,因为这将于下周在我的实习期所在公司的应用商店中作为测试版发布。

提前。

编辑:

这次我会尝试用图片来展示它。 首先我看到的是虚拟机的视图 http://imageshack.us/photo/my-images/194/schermafbeelding2011052l。 .png/ 之后我可以按带有箭头的按钮,然后我可以选择我想要做的事情。 http://imageshack.us/photo/my-images/822/schermafbeelding2011052r。 .png/ 出现一个活动指示器,并在操作完成后停止。(这与每 1 秒检查一次的 NStimer 有关) http://imageshack.us/photo/my-images/828/schermafbeelding2011052y。 .png/ http://imageshack.us/photo/my-images/811/schemafbeelding2011052t.png/ 但是当我尝试在 2 个或更多虚拟机上执行操作时,我选择的最后一行上的活动指示器旋转* x 更快(取决于我发送的操作数。2 个操作意味着它旋转速度快 2 倍。(太奇怪了)

..我希望这足以让你理解我现在的意思 =)

I got an table which is filled with VM's and i have 2 variable of the datatype NSIndexPath called:
selectedindexpath(the row the user clicks on) and
selectedindexpathFortheVMtoTurnOn(so it knows which row to reload when the VM went on);
which is both made in the .h as @paramters(retain) ..

i got a function that turns on the VM's and a function that CHECKS every 1 sec with a NSTimer if the guest is finally on then it reloads the row of selectedindexpathFortheVMtoTurnOn
im doing the same for OFF/REBOOT but i have got a problem with this.. im not able to request an action for more then 1 VM.. because it is overwriting the selectedindexpathFortheVMtoTurnOn value with the last row which i sent an action to and by doing so the table responds wierd and the app crashes..
so thats why i want to give the indexpath.row value as parameters with the NSTimer to the function that checks every 1 sec i have tried a few things but none have worked.. below the code of how i am giving the parameters

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

and the function:

-(void)gettheguestyouaskedforTOTURNON:(NSIndexPath *)therow

and when i try to do a NSLog("%d",therow.row); it crashes...

and with NSLog("%d",therow); i get a whole diffrent value of the selectedindexpathFortheVMtoTurnOn that it used to had..

what am i doing wrong.?

sorry if its a wall of text. but i realy need to fix this problem as this is getting released as BETA nextweek in the appstore for the company where my traineeperiode is.

ty in advance.

EDIT:

i will try to show it with pictures this time.
At first im at the view with VM's
http://imageshack.us/photo/my-images/194/schermafbeelding2011052l.png/
after that i can press on the button with the arrow and i get to choose what i want to do.
http://imageshack.us/photo/my-images/822/schermafbeelding2011052r.png/
an activity indicator appears and it stops when the action is done.(which has to do with the NStimer that checks every 1 sec)
http://imageshack.us/photo/my-images/828/schermafbeelding2011052y.png/
http://imageshack.us/photo/my-images/811/schermafbeelding2011052t.png/
but when i try to do an action at 2 or more VM's the activity indicator on the last row i selected spins *x faster(depends on how manny actions i send.. 2 actions means it spins 2 times faster..(so weird)

.. i hope this is enough for you to understand what i mean now =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一口甜 2024-11-16 17:52:36

NSTimer 对象触发的方法始终将计时器作为参数。你可以像这样得到行。

-(void)gettheguestyouaskedforTOTURNON:(NSTimer *)timer {
    NSIndexPath *indexPath = (NSIndexPath*)[timer userInfo];

    NSLog(@"%d", indexPath.row);
}

The method triggered by an NSTimer object always has the timer as the argument. You can get the row like this.

-(void)gettheguestyouaskedforTOTURNON:(NSTimer *)timer {
    NSIndexPath *indexPath = (NSIndexPath*)[timer userInfo];

    NSLog(@"%d", indexPath.row);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文