相关疑难解决方法(0)

如何通过点击任何地方解除数字键盘键盘

我想知道最简单的代码,当点击数字键盘外的任何地方时,它会关闭数字键盘键盘.在文本字段中输入数字是一个简单的应用程序,然后用户可以在用户完成在文本字段上键入数字后关闭键盘.谢谢!:)

iphone xcode numbers uitextfield ios

51
推荐指数
4
解决办法
6万
查看次数

覆盖Swift 2中的func错误

XCode 6中的此代码没有错误,但在XCode 7(Swift 2)中发生了此错误:

方法不会覆盖其超类中的任何方法

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        /* Called when a touch begins */

}
Run Code Online (Sandbox Code Playgroud)

删除override单词时发生此错误:

方法'的touchesBegan(::) withEvent'与目标C选择'的touchesBegan:withEvent:方法'与方法冲突'的touchesBegan( :从超类的UIResponder'withEvent :)'具有相同的目标C选择

swift swift2

42
推荐指数
1
解决办法
2万
查看次数

'Set <NSObject>'没有名为'anyObject'的成员. - Xcode 6.3

我正在检查是否已选择元素.

func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
    // First, see if the game is in a paused state
    if !gamePaused
    {
        // Declare the touched symbol and its location on the screen
        let touch = touches.anyObject! as? UITouch
        let location = touch.locationInNode(symbolsLayer)
Run Code Online (Sandbox Code Playgroud)

这个以前在Xcode 6.2中编译得很好但是有了6.3更新,"let touch = touches.anyObject!as?UITouch"这一行引发了错误:

'Set'没有名为'anyObject'的成员

我已经阅读了许多类似的问题,但我似乎无法理解"要使用价值,你需要首先解开".特别是因为答案似乎集中在通知上.

非常感谢.w ^

xcode set nsobject ios swift

23
推荐指数
1
解决办法
1万
查看次数

'set'<NSObject>没有名为'anyObject'的成员

今天我用Swift 1.2更新了xcode我的代码在Swift 1.1上工作得很好但是当我更新时我得到了这个错误:

'Set'没有名为'anyObject'的成员

这是我的代码:

override public func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
    let location:CGPoint? = touches.anyObject()?.locationInView(self)
    if let loc = location {
        if (!CGRectContainsPoint(ScaleRect(self.bounds, n: 2.0), loc)) {
            self.highlighted = false
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

你们有一个想法,我该如何解决这个问题?

object member named swift

11
推荐指数
1
解决办法
7244
查看次数

Swift 2:'Set <UITouch>'类型的值没有成员'anyObject'

我检查了我的旧游戏,我想在Swift 2.0中更新它.当我试图修复它时,Xcode发现了一个错误.错误是类型'Set'的值在此代码行中没有成员'anyObject':

var touch:UITouch = touches.anyObject() as! UITouch
Run Code Online (Sandbox Code Playgroud)

功能:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {

    self.runAction(SKAction.playSoundFileNamed("torpedo.mp3", waitForCompletion: false))

    var touch:UITouch = touches.anyObject() as! UITouch //<-- Here is Error
    var location:CGPoint = touch.locationInNode(self)

    var torpedo:SKSpriteNode = SKSpriteNode(imageNamed: "torpedo")
    torpedo.position = player.position

    torpedo.physicsBody = SKPhysicsBody(circleOfRadius: torpedo.size.width/2)
    torpedo.physicsBody!.dynamic = true
    torpedo.physicsBody!.categoryBitMask = photonTorpedoCategory
    torpedo.physicsBody!.contactTestBitMask = alienCategory
    torpedo.physicsBody!.collisionBitMask = 0
    torpedo.physicsBody!.usesPreciseCollisionDetection = true

    var offset:CGPoint = vecSub(location, b: torpedo.position)

    if (offset.y < 0){
        return

    self.addChild(torpedo)

    var direction:CGPoint = …
Run Code Online (Sandbox Code Playgroud)

uitouch sprite-kit skspritenode swift swift2

7
推荐指数
1
解决办法
4376
查看次数

方法不会覆盖它的超类中的任何方法

当我收到此错误时,我正在尝试创建一个新的覆盖功能:方法不会覆盖它的超类中的任何方法

我已经尝试删除覆盖部分,但这只会给我一个错误.

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {

    let touch : UITouch! = touches.anyObject() as! UITouch

    location = touch.locationInView(self.view)

    person.center = location
}

override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {

    let touch : UITouch! = touches.anyObject() as! UITouch

    location = touch.locationInView(self.view)

    person.center = location

}
Run Code Online (Sandbox Code Playgroud)

touchesmoved touchesbegan swift

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

Swift 1.2 - > NSSet - >不兼容的类型

好的,Swift 1.2发生了什么?我最近更新并突然发现我的项目全是红色的.是否已删除与NSSets的兼容性或什么?我该如何解决?

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
Run Code Online (Sandbox Code Playgroud)

结果:

Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent) -> ()'
Run Code Online (Sandbox Code Playgroud)

ios swift

0
推荐指数
1
解决办法
386
查看次数