小编lot*_*osn的帖子

调用中的额外参数userinfo

使用Swift语言从xCode获取编译错误消息:"调用中的额外参数userinfo".问题是如何使用来自计时器的userInfo数据到通知中心的参数"userInfo".

    func onSetAudioWithTrackIndex(CurrentTrackIndex:Int, urlAudio: String){

    ........
    //try to pass currentTrackIndex data to timerfire
    playTimeClock = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: "onSetPlayProgressTime:", userInfo: CurrentTrackIndex, repeats: true)

}

//Timerfire
func onSetPlayProgressTime(timer: NSTimer){

    var currentTime = mediaPlayer.currentPlaybackTime
    var playDuration = mediaPlayer.duration

    var trackIndexDict = ["trackIndex" : timer.userInfo]

    ................

    if currentTime == playDuration{                   
            NSNotificationCenter.defaultCenter().postNotificationName(MPMoviePlayerPlaybackDidFinishNotification, object: self, userInfo: trackIndexDict)
    }


    return
}
Run Code Online (Sandbox Code Playgroud)

notifications timer userinfo swift

4
推荐指数
1
解决办法
2050
查看次数

标签 统计

notifications ×1

swift ×1

timer ×1

userinfo ×1