mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
85 lines
2.4 KiB
Swift
85 lines
2.4 KiB
Swift
//
|
|
// MenuTableViewController.swift
|
|
// librx
|
|
//
|
|
// Created by Yunlong Zheng on 15/8/4.
|
|
// Copyright (c) 2015年 librx. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol MenuViewControllerDelegate : class {
|
|
func menuViewControllerDidSelectLogout(controller:MenuTableViewController)
|
|
func menuViewControllerDidSelectLogin(controller:MenuTableViewController)
|
|
}
|
|
|
|
class MenuTableViewController: UITableViewController {
|
|
|
|
@IBOutlet weak var topMenuLabel: UILabel!
|
|
@IBOutlet weak var recentMenuLabel: UILabel!
|
|
@IBOutlet weak var bookmarkMenuLabel: UILabel!
|
|
@IBOutlet weak var loginMenuLabel: UILabel!
|
|
@IBOutlet weak var loginButton: UIButton!
|
|
|
|
weak var delegate: MenuViewControllerDelegate?
|
|
private var loginAction : LoginAction?
|
|
private var loginStateChange: LoginStateHandler?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
loginStateChange = LoginStateHandler(handler: { [weak self](state) -> () in
|
|
|
|
if state == .LoggedIn {
|
|
self?.loginButton.titleLabel?.text = "注销"
|
|
self?.loginButton.setTitle("注销", forState: UIControlState.Application)
|
|
} else {
|
|
self?.loginButton.titleLabel?.text = "登陆"
|
|
self?.loginButton.setTitle("登陆", forState: UIControlState.Application)
|
|
}
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
@IBAction func topMenuPressed(sender: AnyObject){
|
|
}
|
|
|
|
@IBAction func recentMenuPressed(sender: AnyObject){
|
|
}
|
|
|
|
@IBAction func bookmarkMenuPressed(sender: AnyObject){
|
|
}
|
|
|
|
@IBAction func loginMenuPressed(sender: AnyObject){
|
|
|
|
if LocalStore.accessToken() == nil {
|
|
loginAction = LoginAction(viewController: self, completion: { [weak self] () -> () in
|
|
if let strongSelf = self {
|
|
strongSelf.dismissViewControllerAnimated(true, completion: nil)
|
|
strongSelf.delegate?.menuViewControllerDidSelectLogin(strongSelf)
|
|
}
|
|
})
|
|
} else {
|
|
let _ = LogoutAction()
|
|
dismissViewControllerAnimated(true, completion: nil)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@IBAction func unwindToHome(segue: UIStoryboardSegue) {
|
|
|
|
}
|
|
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
|
|
|
|
}
|