티스토리 뷰

Programming/Swift

Swift4 tip 2

파란크리스마스 2019. 12. 17. 13:49
728x90

출처

UITableView 초기화

class MainViewController: UIViewController {
    
    override func loadView() {
        super.loadView();
        
        self.initWebView(activityIndicator: self.activityIndicator1)
        self.setUrl(hostUrl: MainViewController.url_archim_host, baseUrl: MainViewController.url_archim_base, appUrl: url_archim)
        
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        //appDelegate.viewController = self
        
        //current_orientation = UIInterfaceOrientationMask.Portrait
        
        // 배경색
        self.navigationController?.navigationBar.barTintColor = UIColor.white
        /*
        // 중앙타이틀
        self.navigationController?.navigationBar.topItem?.title = "중앙타이틀"
        // 좌우 글자색
        self.navigationController?.navigationBar.tintColor = UIColor.red
        // 왼쪽 타이틀
        self.navigationItem.leftBarButtonItem?.title = "왼쪽메뉴"
        */
        
        /*
        // titleView로 사용할 Label을 생성
        var frame = CGRect(x: 0, y: 0, width: 200, height: 21)
        let label = UILabel(frame: frame)
        label.text = "이것을 타이틀로 사용합니다"
        // viewController의 titleView를 생성한 Label로 셋업
        self.navigationController?.navigationBar.topItem?.titleView = label
        */
        
        // 중앙
        // let logo = UIImage(named: "main_logo.png")
        let logo = Utiltiy.resizeImage(image: UIImage(named: "main_logo.png")!, targetSize: CGSize(width: 140, height: 32))
        let imageView = UIImageView(image: logo)
        self.navigationItem.titleView = imageView
        
        //
        let leftBarItemImage = Utiltiy.resizeImage(image: UIImage(named: "main_gnb.png")!, targetSize: CGSize(width: 50, height: 50))
        self.navigationItem.leftBarButtonItem?.tintColor = UIColor(rgb: 0x636363)
        self.navigationItem.leftBarButtonItem?.image = leftBarItemImage;
        self.navigationItem.leftBarButtonItem?.imageInsets = UIEdgeInsets(top: 0, left: -18, bottom: 0, right: 0)
        
        //
        let rightBarItemImage = Utiltiy.resizeImage(image: UIImage(named: "main_list.png")!, targetSize: CGSize(width: 50, height: 50))
        self.navigationItem.rightBarButtonItem?.tintColor = UIColor(rgb: 0x636363)
        self.navigationItem.rightBarButtonItem?.image = rightBarItemImage;
        self.navigationItem.rightBarButtonItem?.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -18)
 
        /*
        // setTitlePositionAdjustment 함수 호출
        self.navigationItem.leftBarButtonItem?.setTitlePositionAdjustment(UIOffset(horizontal: 30, vertical: 30), for: UIBarMetrics.compact)
        */
        
        /*
        // UIBarButtonItem 추가
        // http://mtsparrow.blogspot.com/2016/01/blog-post.html
        let leftTarget = self.navigationItem.leftBarButtonItem?.target
        let leftAction = self.navigationItem.leftBarButtonItem?.action
        let leftButton = UIBarButtonItem(image: UIImage (named: "main_gnb.png"), style: UIBarButtonItem.Style.plain, target: leftTarget, action: leftAction)
        let negativeSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        negativeSpacer.width = -16
        //self.navigationItem.leftBarButtonItem = logo2
        self.navigationItem.setLeftBarButtonItems([negativeSpacer, leftButton], animated: false)
        */
    }

UITableViewController - Row 선택

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        // 선택된 index 순서 출력
        // print(indexPath.row)
        
        let cell = super.tableView(tableView, cellForRowAt: indexPath) as! UITableViewVibrantCell
        
        if case cell.reuseIdentifier = "menu_quality" {
            let storyboard = UIStoryboard(name : "MainStoryboard_iPhone", bundle : nil)
            let nextViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! NiaspMainViewController
            self.present(nextViewController, animated: true, completion: nil)
        }
    }

uitableview에서 cell클릭시 다음 view로 데이터 넘기기

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let vc = segue.destination as! infoPUBG_kind
        //vc.value2 = value
        let cell = sender as! UITableViewCell
        let indexPath = tableView.indexPath(for: cell)
        vc.kindTitle = infoList[(indexPath?.row)!]//내가누른 cell의 text
        vc.kindRow = (indexPath?.row)!//내가누른 cell의 row값
    }

SideMenu

SideMenuNavigationController.swift

@objcMembers
open class SideMenuNavigationController: UINavigationController {

SideMenuManager

@objcMembers public class SideMenuManager : NSObject {

    @objc public enum PresentDirection : Int {

        case left

        case right
    }

    /// Default instance of SideMenuManager.
    public static let `default`: SideMenu.SideMenuManager

    /// Default instance of SideMenuManager (objective-C).
    public class var defaultManager: SideMenu.SideMenuManager { get }

    /// The left menu.
    open var leftMenuNavigationController: SideMenu.SideMenuNavigationController?

    /// The right menu.
    open var rightMenuNavigationController: SideMenu.SideMenuNavigationController?

    /**
         Adds screen edge gestures for both left and right sides to a view to present a menu.
    
         - Parameter toView: The view to add gestures to.
    
         - Returns: The array of screen edge gestures added to `toView`.
         */
    public func addScreenEdgePanGesturesToPresent(toView view: UIView) -> [UIScreenEdgePanGestureRecognizer]

    /**
        Adds screen edge gestures to a view to present a menu.
        
        - Parameter toView: The view to add gestures to.
        - Parameter forMenu: The menu (left or right) you want to add a gesture for.
    
        - Returns: The screen edge gestures added to `toView`.
        */
    public func addScreenEdgePanGesturesToPresent(toView view: UIView, forMenu side: SideMenu.SideMenuManager.PresentDirection) -> UIScreenEdgePanGestureRecognizer

    /**
     Adds a pan edge gesture to a view to present menus.
     
     - Parameter toView: The view to add a pan gesture to.
     
     - Returns: The pan gesture added to `toView`.
     */
    public func addPanGestureToPresent(toView view: UIView) -> UIPanGestureRecognizer
}

extension SideMenuManager {

    @available(*, deprecated, renamed: "leftMenuNavigationController")
    open var menuLeftNavigationController: SideMenu.SideMenuNavigationController?

    @available(*, deprecated, renamed: "rightMenuNavigationController")
    open var menuRightNavigationController: SideMenu.SideMenuNavigationController?

SideMenu 버튼 클릭 이벤트

import SideMenu

class SideMenuTableViewController: UITableViewController {

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        print(indexPath.row)
        
        if case indexPath.row = 3 {
            //SettingsMainViewController *comChange = [[SettingsMainViewController alloc] init];
            //[self.navigationController pushViewController:comChange animated:NO];
            //var comChange : SettingsMainViewController
            
            /*
            let storyboard : UIStoryboard = self.storyboard!
            let nextView = storyboard.instantiateViewController(identifier: "MainStoryboard_iPhone")
            self.present(nextView, animated: true, completion: nil)
            */
            
            let storyboard = UIStoryboard(name : "MainStoryboard_iPhone", bundle : nil)
            let nextView = storyboard.instantiateInitialViewController()
            self.present(nextView!, animated: true, completion: nil)
        }
    }

SideMenuNavigationControllerDelegate

extension MainViewController: SideMenuNavigationControllerDelegate {
    
    func sideMenuWillAppear(menu: SideMenuNavigationController, animated: Bool) {
        print("SideMenu Appearing! (animated: \(animated))")
    }
    
    func sideMenuDidAppear(menu: SideMenuNavigationController, animated: Bool) {
        print("SideMenu Appeared! (animated: \(animated))")
    }
    
    func sideMenuWillDisappear(menu: SideMenuNavigationController, animated: Bool) {
        print("SideMenu Disappearing! (animated: \(animated))")
    }
    
    func sideMenuDidDisappear(menu: SideMenuNavigationController, animated: Bool) {
        print("SideMenu Disappeared! (animated: \(animated))")
    }
}

activeDelegate (SideMenuNavigationController.swift)

@objcMembers
open class SideMenuNavigationController: UINavigationController {

    /// Delegate for receiving appear and disappear related events. If `nil` the visible view controller that displays a `SideMenuNavigationController` automatically receives these events.
    public weak var sideMenuDelegate: SideMenuNavigationControllerDelegate?

... 생략 ...

private extension SideMenuNavigationController {

    weak var activeDelegate: SideMenuNavigationControllerDelegate? {
        guard !view.isHidden else { return nil }
        if let sideMenuDelegate = sideMenuDelegate { return sideMenuDelegate }
        return findViewController as? SideMenuNavigationControllerDelegate
    }

    var findViewController: UIViewController? {
        foundViewController = foundViewController ?? presentingViewController?.activeViewController
        return foundViewController
    }



댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함