小编and*_*fan的帖子

iOS 11 - 成为第一响应者而不是打开键盘

我正在使用swift 2.2 for iOS app.

我有一个UIButton,其中有一个.TouchUpInside触发UITextField成为的事件first responder.

以下是输入:

    self.manualInput = BrandTextField(y: 0, parentWidth: self.view.frame.width)
    self.manualInput.returnKeyType = .Search
    self.manualInput.autocorrectionType = .No

    self.manualInput.hidden = true
    self.manualInput.text = ""
    self.manualInput.delegate = self
    self.manualInput.autocapitalizationType = .AllCharacters
    self.manualInput.moveX(0)
    self.manualInput.changeWidth(self.view.frame.width)
    self.manualInput.layer.cornerRadius = 0

    self.backgroundView.addSubview(self.manualInput)
Run Code Online (Sandbox Code Playgroud)

下面是按钮:

self.keyboardButton = ActionButton(x: Dimensions.xScaleValue(170), y: Dimensions.yScaleValue(495), onTitle: "Enter code", offTitle: "Enter code", onImage: "manual_entry", offImage: "manual_entry", imageOn: true, action: {
    self.manualInput.becomeFirstResponder()
    print("Open the input")
})
self.backgroundView.addSubview(self.keyboardButton)
Run Code Online (Sandbox Code Playgroud)

我也有这两个观察者:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyBoardWillShow), name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, …
Run Code Online (Sandbox Code Playgroud)

ios swift ios11

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

将 userInfo [AnyHashable: Any] 转换为 [String: Any]

我收到通知didreceiveRemoteNotification但无法将 userInfo 转换为 [String: Any] 类型的字典

\n\n
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {\n    let dict = userInfo as! [String: Any]\n    if let response = dict["message"] as? [String: Any], let baseResponse = Mapper<NotificationModel>().map(JSON: response) {\n      //do some stuff\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我尝试将 dict["message"] 转换为![字符串:任何] 发生错误,并显示:

\n\n

无法将类型“__NSCFString”(0x1cfa84f90)的值转换为“NSDictionary”(0x1cfa85bc0)。

\n\n

当我在控制台中打印它时,这是 dict["message"] :

\n\n
\xe2\x96\xbf Optional<Any>\n  - some : {"sender":\n\n{"avatar_url":"http:\\/\\/api.moneyar.com\\/APIs\\/images\\/15783070400.jpg","user_id":"15783","name":"mahdi moqadasi"}\n\n,"conversation_id":"15783"\n\n,"message_id":103597,\n\n"time":1546778745,\n\n"type":1,"message":"foo"\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

push-notification apple-push-notifications swift

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

Google Cloud Function 访问外部数据库

我想从Google Cloud FunctionFirebase Cloud Function访问外部数据库 (mongodb) 。我不想每次都创建数据库连接。是否有一个选项可以将数据库连接存储在全局变量中并在每次调用中使用它。

google-cloud-functions

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

如何将 R.swift 用于字符串和颜色

所以我有一个简单的问题。我搜索了很多,但我的问题没有这么明确的答案。如何将 R.swfit 用于颜色和本地化字符串?R.swift 完全识别我的图像和字体,但我如何将它们用于我的颜色和本地化。我有这么多的颜色和本地化字符串在我的项目,但R.stringR.color是空的所有

typechecking ios swift

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