How to pass the Selector parameter in Swift and the selector parameter in swift
@ Selector of Objective-C is replaced by the Selector struct in Swift. In Swift, we can use string constants to construct Selector. For example:
let mySelector: Selector = "tappedButton:"
Because the string will be automatically converted to Selector. The following is an example:
// SwiftmyButton.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)func buttonTapped(sender: UIButton!) { // custom code...}
(Do not forget to add a colon if you have parameters :)
:-]
Nsttor
{UIView * oldView = [[timer userInfo] objectForKey: @ "oldView"]; UIView * newView = [[timer userInfo] objectForKey: @ "newView"]; [UIView animateWithDuration: 2.0 delay: 0 options: UIViewAnimationOptionAllowUserInteraction animations: ^ {oldView. alpha = 0.0; newView. alpha = 1.0 ;}} as shown in the preceding figure, nstmer stores the parameter-passing object in the userInfo Dictionary of nstmer when passing parameters to @ selector (onTimer, use this dictionary in-(void) onTimer :( NSTimer *) timer. In fact, this is the general form of passing parameters to the @ selector object on the iphone.
Q: How to pass parameters to the @ selector function of the IPhone through nsttor
Hello, the query result is as follows: NSMutableDictionary * dict = [[NSMutableDictionary alloc] init]; if (oldView! = Nil) {[dict setObject: oldView forKey: @ "oldView"];} if (newView! = Nil) {[dict setObject: newView forKey: @ "newView"];} [NSTimer scheduledTimerWithTimeInterval: 0.0 target: self selector: @ selector (onTimer :) userInfo: dict repeats: NO]; [dict release];-(void) onTimer :( NSTimer *) timer {UIView * oldView = [[timer userInfo] objectForKey: @ "oldView"]; UIView * newView = [[timer userInfo] objectForKey: @ "newView"]; [UIView animateWithDuration: 2.0 delay: 0 options: UIViewAnimationOptionA LlowUserInteractionanimations: ^ {oldView. alpha = 0.0; newView. alpha = 1.0 ;}} as shown in the preceding figure, nstmer stores the parameter-passing object in the userInfo Dictionary of nstmer when passing parameters to @ selector (onTimer, use this dictionary in-(void) onTimer :( NSTimer *) timer. In fact, this is the general form of passing parameters to the @ selector object on the iphone.