Swift 常用技術(shù)總結(jié)

特定導(dǎo)航欄隱藏

override func viewDidLoad() {
     super.viewDidLoad()
     self.navigationController?.delegate = self
 }
extension MLMineTableViewController:UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
     let vcClass =  viewController.isKind(of:       
     MLMineTableViewController.superclass()!)
     self.navigationController?.navigationBar.isHidden = vcClass
     navigationController.setNavigationBarHidden(vcClass, animated: animated)
    }
}

ScrollView,TableView滑動(dòng)鍵盤隱藏

scrollView.keyboardDismissMode = .OnDrag
or
scrollView.keyboardDismissMode = .Interactive

浮點(diǎn)數(shù)取整

public func ceil(_: Double) -> Double  //取上整
public func floor(_: Double) -> Double //取下整

TableView的cell自適應(yīng)高度,不用單獨(dú)設(shè)置每個(gè)cell的高度

 self.tableView.rowHeight = UITableViewAutomaticDimension
 self.tableView.estimatedRowHeight = 200; //預(yù)計(jì)高度

枚舉類型

@objc enum DrugStoreType: Int {
    case undefined = 0
    case online = 1
    case offlinee = 2
    var text: String {
        switch self {
        case .online:
            return "線上藥店"
        case .offlinee:
            return "線下藥店"
        default:
            return ""
        }
    }
}
let content = DrugStoreType.undefined.text  // 直接顯示枚舉對(duì)應(yīng)的文本

泛型

任務(wù):打印輸出數(shù)組內(nèi)所有的元素。

var stringArray = ["蒼老師", "范老師", "優(yōu)衣庫"]
var intArray = [1, 3, 4, 5, 6]
var doubleArray = [1.0, 2.0, 3.0]
func printStringArray(a: [String]) {         
  for s in a {              
   print(s)        
   } }
func printIntArray(a: [Int]) { 
  for i in a { 
    print(i) 
   } }
func printDoubleArray(a: [Double]) {for d in a { print(d) } }

簡(jiǎn)介版

func printElementFromArray(a: [T]) {        
    for element in a {            
      print(element)        
     } }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容