向 @selector 传递一个对象

发布于 2024-10-06 03:59:01 字数 502 浏览 0 评论 0原文

我在 UIView 上有一个动画块,并且想向我的 animationDidStopSelector 传递一个对象,以便当我的动画完成时,可以从数组中删除该对象。

下面的代码,不起作用。

[UIView setAnimationDidStopSelector:@selector(animationDidStopWithObject:)];
    self.dialogController.view.alpha=1;
[UIView commitAnimations];

    [self.view addSubview:self.dialogController.view];
}

- (void)animationDidStopWithObject:(NSString*)obj {
    [items removeObject:obj];
    [self.tableView reloadData];
}

我如何向我的选择器传递一个对象?

谢谢

I have an animation block on a UIView, and would like to pass my animationDidStopSelector an object, so that when my animation finishes, the object can be removed from an array.

The following code, doesn't work.

[UIView setAnimationDidStopSelector:@selector(animationDidStopWithObject:)];
    self.dialogController.view.alpha=1;
[UIView commitAnimations];

    [self.view addSubview:self.dialogController.view];
}

- (void)animationDidStopWithObject:(NSString*)obj {
    [items removeObject:obj];
    [self.tableView reloadData];
}

How can i pass my selector an object?

Thanks

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

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

发布评论

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

评论(3

你是暖光i 2024-10-13 03:59:01

检查 UIView 参考。您传递给 +setAnimationDisStopSelector: 方法的选择器必须采用以下形式

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

您可以使用动画上下文将对象传递给该选择器(在 +beginAnimations:context: 调用中作为参数传递的 void* 指针)

Check UIView reference. Selector you pass to +setAnimationDisStopSelector: method must be of the form

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

You can pass your object to that selector using animations context (void* pointer passed as parameter in +beginAnimations:context: call)

伊面 2024-10-13 03:59:01

您的选择器需要遵循签名:

- (void)animationDidStop:(NSString *)animationID finish:(NSNumber *)finished context:(void *)context

并传递一个自定义对象,这就是什么context 用于:您使用 [UIView beginAnimations:someId context:yourCustomObject]; 设置它。请注意,yourCustomObject 不会被保留!

Your selector needs to follow the signature:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

And to pass it a custom object, that's what the context is used for: you set it with [UIView beginAnimations:someId context:yourCustomObject];. Note that yourCustomObject is not retained !

忆梦 2024-10-13 03:59:01

您不能只传递带有任意数量参数的任意选择器。如果您检查文档,它需要采用以下形式

(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

:以下是相关文档:

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#// apple_ref/occ/clm/UIView/setAnimationDidStopSelector

You can't just pass an arbitrary selector with an arbitrary number of arguments. If you check the documentation, it needs to be of the form

(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

Here are the relevant docs:

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/setAnimationDidStopSelector:

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