2017-03-23 50 views
0

我正試圖在Swift中實施操作手冊。以下是實現它的代碼。當我執行代碼時,Xcode不會顯示任何錯誤,並且操作表不會出現在模擬器中。非常感謝任何幫助解決這個問題。操作手冊在iPhone模擬器中不起作用

覆蓋FUNC viewWillAppear中(_動畫:BOOL){ super.viewWillAppear(動畫)

func showActionSheet(sender: AnyObject) { 

    let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Choose an option!", preferredStyle: .actionSheet) 

    //Create and add the Cancel action 
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in 
     //Just dismiss the action sheet 
    } 
    actionSheetController.addAction(cancelAction) 

    self.present(actionSheetController, animated: true, completion: nil) 
+0

你的例子有一些格式問題,很難說明你到底在做什麼。糾正這一點,它會更容易幫助。 – kevin

+0

我發現我的問題後,我意識到有格式化問題。我對此很陌生,並會嘗試糾正這個問題。 – spenumatsa

回答

1

提供代碼的方式,它看起來好像你裏面加viewWillAppear的方法/函數。如果這是不是打錯了,你確實設置你的代碼像的是,修改你的代碼看起來像這樣會得到它的工作:

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Choose an option!", preferredStyle: .actionSheet) 

    //Create and add the Cancel action 
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in 
     //Just dismiss the action sheet 
    } 
    actionSheetController.addAction(cancelAction) 

    self.present(actionSheetController, animated: true, completion: nil) 
} 

基本上沒有內部viewWillAppear的方法也是移動你的動作表顯示代碼爲viewDidAppear而不是viewWillAppear