向 @selector 传递一个对象
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 UIView 参考。您传递给 +setAnimationDisStopSelector: 方法的选择器必须采用以下形式
您可以使用动画上下文将对象传递给该选择器(在 +beginAnimations:context: 调用中作为参数传递的 void* 指针)
Check UIView reference. Selector you pass to +setAnimationDisStopSelector: method must be of the form
You can pass your object to that selector using animations context (void* pointer passed as parameter in +beginAnimations:context: call)
您的选择器需要遵循签名:
- (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 thatyourCustomObject
is not retained !您不能只传递带有任意数量参数的任意选择器。如果您检查文档,它需要采用以下形式
:以下是相关文档:
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
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: