Tag: 函数

在另一个类中创build一个函数

我试图通过使用我的视图控制器中的函数在我的自定义tableViewCell类中引发一个函数。 我对如何做到这一点真的很无知,所以我试着写这样的: TableViewCell.timerStarted() 我试图摆脱的function看起来像这样: func timerStarted(){ timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true) } 其中TableViewCell是我的类的名称和timerStarted函数的名称。 这给我一个错误,说它错过了括号内的一个参数。 我很困难,任何build议,将不胜感激。

同时运行两个jquery事件会导致闪烁

我有两个function,我想同时发生。 函数1是一个窗口scrollTop,function2是一个绝对的元素隐藏(#elem1)。 这两个函数在绝对元素(#elem2)放在(#elem1)之后立即发生。 同时运行这些函数执行如下: elem1卷轴顶部 elem1是隐藏的 elem2滚动到顶部 这会导致瞬间闪烁,在ios上闪烁,我想避免它。 我会期望改变函数的顺序会给我期望的结果,但是它不起作用(把#elem1隐藏在scrolltop之前)。 我怎样才能做到这一点? 这与以下主题有关,但我想我会简化它。 转换后的jquery元素闪烁和ios上的scrolltop

返回函数内部无效

我正在尝试创build一个自定义类来点击图片。 在里面,我想创build一个返回一个UIImage的clickPicture函数。 但是, captureStillImageAsynchronously是一个void 。 我怎样才能返回从我收到的图像? 谢谢。 func clickPicture() -> UIImage? { if let videoConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo) { videoConnection.videoOrientation = .portrait stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (sampleBuffer, error) -> Void in if sampleBuffer != nil { let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) let dataProvider = CGDataProvider(data: imageData!) let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: […]

在后台线程上调用函数ios – 嵌套函数调用会发生什么

在我的主要代码(为了显示UIActivityIndi​​catorView)我在背景线程上调用一个函数,foo()。 foo()调用的函数又会如何呢? 这些函数是否也会在同一个后台线程中调用和执行?

在NavigatorIOS – React Native中调用onRightButtonPress的函数

我在反应原生NavigatorIOS中使用onRightButton。 我希望能够调用一个驻留在我所推的组件中的函数,但是我不知道如何实现这个function。 这是一个代码示例: this.props.navigator.push({ component: SingleResultView, title: "SomeTitle", rightButtonIcon: require('image!mapsmarker'), passProps: { userPosition: this.props.userPosition }, onRightButtonPress: () => { SingleResultView.foo(); } // NOT WORKING! }); 我怎样才能做到这一点?

在快速,可以一个函数是一个types?

在按Command + Click研究XCTAssert方法的同时,它看起来像是底层方法是一个具有types的函数(generics被称为T,符合Equatable协议)。 我是否正确地说,如果是这样,函数如何符合协议? 函数types是什么? public func XCTAssertEqual<T : Equatable>(_ expression1: @autoclosure () throws -> ArraySlice<T>, _ expression2: @autoclosure () throws -> ArraySlice<T>, _ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line) 这行是我想解释上面最混乱的: func XCTAssertEqual<T : Equatable>`

在swift中实现函数

我是swift的新手,试图实现一个简单的函数,它将最小和最大数字作为input,并返回一个数组,其中所有数字都在极限内。 我得到一个错误//错误:引用genericstypes'数组'需要在<…>中的参数可能我知道我缺less什么? func serialNumberLimits(minimumNumber n1:Int, maximumNumber n2:Int) -> Array { // Initialized an empty array var array = Int[]() //Initialized a "Temp" variable var temp:Int = 0 for index in n1..n2 { temp += n1 n1++ if index == 1 { array.insert(temp, atIndex: 0) } else { array.insert(temp, atIndex: index-1) } } return array }

Swift中的callback函数语法

我试图传递一个函数到另一个函数,然后让传递的函数传递给它一个variables。 这是我的代码: func showStandardPrompt(prompt:String,view: UIViewController,numberInput: Bool, callback: (()->(String))?) { let alert = UIAlertController(title: "Input Data", message: prompt, preferredStyle: .Alert) alert.addTextFieldWithConfigurationHandler { (textField) in if numberInput { textField.keyboardType = .NumberPad } } let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in let field = alert.textFields![0] as UITextField callback?(field.text!) } alert.addAction(OKAction) let CancelAction = UIAlertAction(title: "Cancel", […]

如何从纯C函数返回值到swift?

我有一个疑问,如何从纯c函数获取返回值swift。 在这里我的代码: 在ViewController.swift // swift文件 var name = getPersonName() 在personList.h // C头文件 char getPersonName(); 在personList.c //纯C文件 #include personList.h char getPersonName() { char* name = "Hello, Swift"; return name; } 在这里,我已经使用MyProjectName-Bridging-Header.h通过网桥链接personList.h文件。 谢谢