0

こんにちは、私はswiftの初心者で、現在、iPadとiPhoneの両方でswift 2.3で行われたプロジェクトに取り組んでいます。ドキュメントにあるようにすべてを行いましたが、何らかの理由で電話番号ボタンを使用したピンク色のログインが画面に表示されません。コードは以下です。

import UIKit
import SwiftSpinner
import Crashlytics
import Alamofire
import SwiftyJSON
import DigitsKit


class ViewController: UIViewController, UITextFieldDelegate {

    var  phoneNum : String?
    let movement: CGFloat = 20.0
    var phoneHeight: CGFloat = 0.0
    var appURLs = AppURLs.sharedInstance
    var loadingView: UIView!
    var Id: Int!
    @IBOutlet weak var username: UITextField!
    @IBOutlet weak var activity: UIActivityIndicatorView!
    @IBOutlet weak var password: UITextField!
    @IBAction func signUpButton(sender: AnyObject) {
        let storyboard = switchStoryboards()
        let vc = storyboard.instantiateViewControllerWithIdentifier("SignUpViewController")
        self.presentViewController(vc, animated: false, completion: nil)
    }

 override func viewDidLoad() {
        super.viewDidLoad()


        configureLoadingView()
        phoneHeight = self.view.frame.height
        UIApplication.sharedApplication().statusBarHidden = true
        self.username.delegate = self
        self.password.delegate = self
        self.slideMenuController()?.removeLeftGestures()
        let usernameImageView = UIImageView()
        if isIphone() {
            usernameImageView.frame = CGRect(x: 0, y: 0, width: 36, height: 20)
        } else {
            usernameImageView.frame = CGRect(x: 0, y: 0, width: 54, height: 30)
        }
        usernameImageView.image = UIImage(named: "Username")
        view.addSubview(usernameImageView)
        username.leftView = usernameImageView
        username.leftViewMode = UITextFieldViewMode.Always

        let passwordImageView = UIImageView()
        if isIphone() {
            passwordImageView.frame = CGRect(x: 0, y: 0, width: 36, height: 20)
        } else {
            passwordImageView.frame = CGRect(x: 0, y: 0, width: 54, height: 30)
        }
        passwordImageView.image = UIImage(named: "Password")
        view.addSubview(passwordImageView)
        password.leftView = passwordImageView
        password.leftViewMode = UITextFieldViewMode.Always

        print("Login view did load loaded")

        let authButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
            if (session != nil) {
                // TODO: associate the session userID with your user model
                let message = "Phone number: \(session!.phoneNumber)"
                let alertController = UIAlertController(title: "You are logged in!", message: message, preferredStyle: .Alert)
                alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: .None))
                self.presentViewController(alertController, animated: true, completion: .None)
            } else {
                NSLog("Authentication error: %@", error!.localizedDescription)
            }
        })
        authButton?.center = self.view.center
        self.view.addSubview(authButton!)


    }

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)
    }

    func configureLoadingView() {
        loadingView = UIView(frame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height))
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        if let _ = touches.first {
            self.view.endEditing(true)
        }
        super.touchesBegan(touches, withEvent:event)
    }

    func textFieldShouldReturn(textField: UITextField) -> Bool {
        if textField.tag == 1 {
            textField.superview?.viewWithTag(2)?.becomeFirstResponder()

        } else {
            textField.resignFirstResponder()
        }

        return true
    }

    func textFieldDidBeginEditing(textField: UITextField) {
        if phoneHeight < 500.0 {
            UIView.animateWithDuration(0.3, animations: {
                self.view.frame = CGRectOffset(self.view.frame, 0, -self.movement)
            })
        }
    }

    func textFieldDidEndEditing(textField: UITextField) {
        if phoneHeight < 500.0 {
            UIView.animateWithDuration(0.3, animations: {
                self.view.frame = CGRectOffset(self.view.frame, 0, self.movement)
            })
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func loginAlerts(messages: String) {
        self.activity.stopAnimating()
        SwiftSpinner.show("Sign in Failed!", animated: false).addTapHandler({
            SwiftSpinner.hide()
            }, subtitle: messages)
    }
    func switchStoryboards() -> UIStoryboard {
        switch UIDevice.currentDevice().userInterfaceIdiom {
        case .Phone:
            // It's an iPhone
            return UIStoryboard(name: "Main", bundle: nil)
        case .Pad:
            return UIStoryboard(name: "StoryboardiPad", bundle: nil)
            // It's an iPad
        case .Unspecified:
            return UIStoryboard(name: "Main", bundle: nil)
            // Uh, oh! What could it be?
        default:
            return UIStoryboard(name: "Main", bundle: nil)
        }
    }

    func isIphone() -> Bool {
        switch UIDevice.currentDevice().userInterfaceIdiom {
        case .Phone:
            // It's an iPhone
            return true
        case .Pad:
            return false
            // It's an iPad
        case .Unspecified:
            return true
            // Uh, oh! What could it be?
        default:
            return true
        }
    }
}
4

0 に答える 0