开发者

Pass @selector an object

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.dialogCo开发者_Go百科ntroller.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


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)


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 !


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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜