xcode – 以编程方式切换视图swift
发布时间:2020-12-15 02:00:30 所属栏目:百科 来源:网络整理
导读:我正在Xcode 6测试版中尝试苹果的新语言swift。当我按下表格视图单元格时,我试图以编程方式切换视图,尽管它所做的只是拉一个空白的黑色屏幕。在我的代码中,我发表了一些不起作用的事情。他们只会使iOS模拟器崩溃。我的代码: // ViewController.swift //
我正在Xcode 6测试版中尝试苹果的新语言swift。当我按下表格视图单元格时,我试图以编程方式切换视图,尽管它所做的只是拉一个空白的黑色屏幕。在我的代码中,我发表了一些不起作用的事情。他们只会使iOS模拟器崩溃。我的代码:
// ViewController.swift // Step-By-Step Tip Calculator // Created by Dani Smith on 6/17/14. // Copyright (c) 2014 Dani Smith Productions. All rights reserved. import UIKit var billTotalPostTax = 0 class BillInfoViewController: UIViewController { //outlets @IBOutlet var totalTextField: UITextField @IBOutlet var taxPctLabel: UILabel @IBOutlet var resultsTextView: UITextView @IBOutlet var taxPctTextField : UITextField //variables var billTotalVar = "" var taxPctVar = "" //actions override func viewDidLoad() { super.viewDidLoad() refreshUI() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func stepOneNextPressed(sender : AnyObject) { billTotalVar = totalTextField.text taxPctVar = taxPctTextField.text } @IBAction func calculateTipped(sender : AnyObject) { tipCalc.total = Double(totalTextField.text.bridgeToObjectiveC().doubleValue) let possibleTips = tipCalc.returnPossibleTips() var results = "" for (tipPct,tipValue) in possibleTips { results += "(tipPct)%: (tipValue)n" } resultsTextView.text = results } /* @IBAction func taxPercentageChanged(sender : AnyObject) { tipCalc.taxPct = String(taxPctTextField.text) / 100 refreshUI() }*/ @IBAction func viewTapped(sender : AnyObject) { totalTextField.resignFirstResponder() } let tipCalc = TipCalculatorModel(total: 33.25,taxPct: 0.06) func refreshUI() { //totalTextField.text = String(tipCalc.total) } } class RestaurantTableViewController: UITableViewController { override func tableView(tableView: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!) { let row = indexPath?.row println(row) //let vc:BillInfoViewController = BillInfoViewController() //let vc = self.storyboard.instantiateViewControllerWithIdentifier("billInfo") as UINavigationController //self.presentViewController(vc,animated: true,completion: nil) } } 非常感谢你的帮助。 解决方法
我只是想出来了我不得不做
let vc = self.storyboard.instantiateViewControllerWithIdentifier("billInfo")` 成为 let vc : AnyObject! = self.storyboard.instantiateViewControllerWithIdentifier("billInfo") 沉默警告。然后我将presentViewController更改为showViewController,它工作。这是我完成的课程: class RestaurantTableViewController: UITableViewController { override func tableView(tableView: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!) { let row = indexPath?.row println(row) let vc : AnyObject! = self.storyboard.instantiateViewControllerWithIdentifier("billInfo") self.showViewController(vc as UIViewController,sender: vc) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |