我最近更新了当前版本的 GoogleSignIn,但找不到解决我面临的这个问题的方法。我收到的错误是:“GIDSignInResult”类型的值没有成员“身份验证”
func googleSignInAction(){
guard let clientID = FirebaseApp.app()?.options.clientID else { return }
let config = GIDConfiguration(clientID: clientID)
GIDSignIn.sharedInstance.signIn(withPresenting: self) { user, error in
if let error = error {
print("There is an error signing the user in ==> \(error)")
return
}
guard let authentication = user?.authentication, let idToken = authentication.idToken else { return }
let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { authResult, error in
if error != nil {
print(error)
} else {
self.email = …Run Code Online (Sandbox Code Playgroud) 这应该很容易做到,而且在 android(使用 LinearLayout)中也很容易,但我不知道如何在 ios 中做到这一点。
我有 UIView,我想在其中添加一些动态高度子视图。子视图从 xib 文件加载并包含 2 个具有动态高度的 UILabels。
class Subview: UIView {
@IBOutlet var contentView: UIView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var desc: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
self.commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
}
fileprivate func commonInit() {
Bundle.main.loadNibNamed("Subview", owner: self, options: nil)
addSubview(contentView)
self.contentView.frame = self.bounds
self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
}
Run Code Online (Sandbox Code Playgroud)
和子视图是这样添加的
var containerView: UIView
func setupView() {
let subview1 = Subview()
subview1.title = "Some …Run Code Online (Sandbox Code Playgroud) 以下代码在 a 中工作UIViewController,但在我的类中,UITableViewCell它给出了错误
使用未解析的标识符“存在”。
代码是一个动作:
@IBAction func linkAction(_ sender: Any) {
let linkString = self.linkText.text
if let requestUrl = URL(string: linkString!) {
let safariVC = SFSafariViewController(url: requestUrl)
present(safariVC, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
有解决办法吗?
我使用 URLSession 解析 JSON 并将其映射到 Codable ,但我无法在 JSON 数据内部获取结果数组以在表视图中显示它。我的问题是如何获取结果并从中创建一个对象以在表视图中使用。
JSON 数据:
{
"result": [
{
"Id": 5,
"Title": "test",
"EnTitle": "Story and Novel"
},
{
"Id": 38,
"Title": "test",
"EnTitle": " Motivational"
}
],
"status": {
"httpStatusCode": 200
}
}
Run Code Online (Sandbox Code Playgroud)
JSON 模型:
struct Result : Decodable {
let status: status
let result: result
}
struct status : Decodable {
let httpStatusCode: Int
}
struct result : Decodable {
let Id: Int
let Title: String
let EnTitle: …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码从 VC 调用 Scene Delegate func 并收到错误
线程 1:信号 SIGABRT
let sceneDelegate = UIApplication.shared.delegate as! SceneDelegate
sceneDelegate.initializeFirstViewController()
Run Code Online (Sandbox Code Playgroud)
有什么办法可以SceneDelegate从 VC 调用 func 吗?
我试图在我的键盘上实现一个显示/隐藏,但问题是当我显示我的键盘它超过我的视图,更重要的是它超过我的文本字段和按钮,所以我可以输入,我只是不能按我的按钮.
以下是键盘前的屏幕截图:
这是键盘出现的时间:
如你所见,我看不到文字字段和按钮.
这是我的代码 viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(CommentsController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(CommentsController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
Run Code Online (Sandbox Code Playgroud)
以下是方法:
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.view.frame.origin.y -= keyboardSize.height
}
}
}
@objc func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.view.frame.origin.y += keyboardSize.height
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我的键盘会超出我的视线?以及如何解决?
我执行 2 个 http 请求并从它们异步获取数据。接收到数据后,我需要根据它形成一个数组并重新加载表,我该怎么做?代码:
override func viewDidLoad() {
super.viewDidLoad()
ApiManager.shared.getStocks(completion: {result in
DispatchQueue.main.async {
switch result {
case .success(let stocks):
self.stocks = stocks
case .failure:
self.stocks = []
}
print(self.stocks.count)
}
})
ApiManager.shared.getDowJones (completion: { result in
DispatchQueue.main.async {
switch result {
case .success(let dowJones):
self.dowJones = dowJones
case .failure:
self.dowJones = []
}
print(self.dowJones.prefix(10))
}
})
}
Run Code Online (Sandbox Code Playgroud) ios ×8
swift ×8
xcode ×3
autolayout ×1
cocoapods ×1
json ×1
swift3 ×1
uikeyboard ×1
uitableview ×1
uiview ×1
xib ×1