gpt4 book ai didi

ios - 未在 UIBarButtonItem 选择器内调用prepareForSegue

转载 作者:行者123 更新时间:2023-11-30 14:16:42 25 4
gpt4 key购买 nike

这是我注册 UIBarButtonItems 及其选择器函数的代码。

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.

var edit = UIBarButtonItem(title: "Edit", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("editTruck"))
let delete = UIBarButtonItem(title: "Delete", style: UIBarButtonItemStyle.Plain, target: self, action: "deleteTruck")
let menu = UIBarButtonItem(image: UIImage(named: "menu"), style: UIBarButtonItemStyle.Plain, target: self.revealViewController(), action: "rightRevealToggle:")

self.navigationItem.rightBarButtonItems = [menu,delete,edit]

self.title = truckName.text

self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
}

func editTruck(){

println("insdie edittruck")

self.performSegueWithIdentifier("editTruck", sender: self)

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
println("inside prepare")
if segue.identifier == "editTruck"{
let vc = segue.destinationViewController as? UINavigationController
let topView = vc?.topViewController as! AddTruckViewController
topView.truckNameValue = name.text!
topView.totalFuelupsValue = totalFuelups.text!
topView.totalDistanceTrackedValue = totalDistanceTracked.text!
topView.truckYearValue = truckYear.text!
topView.truckMakeValue = truckMake.text!
topView.truckModelValue = truckModel.text!
topView.truckImagevalue = truckImage.image!
topView.engineMakeValue = engineMake.text!
topView.engineModelValue = engineModel.text!
topView.horsePowerValue = horsePower.text!
topView.axleValue = axle.text!
topView.trailerTypeValue = trailerType.text!
topView.steerTireMakeValue = steerTireMake.text!
topView.steerTireModelValue = steerTireModel.text!
topView.steerTireSizeValue = steerTireSize.text!
topView.driveTireMakeValue = driveTireMake.text!
topView.driveTireModelValue = driveTireModel.text!
topView.driveTireSizeValue = driveTireSize.text!
topView.transmissionMakeValue = transmissionMake.text!
topView.transmissionModelValue = transmissionModel.text!
topView.distanceUnitValue = distanceUnit.text!
topView.volumeUnitValue = volumeUnit.text!
}
}
}

在IB中,我将控件从TruckSpecsViewController(顶部的黄色图标,因为我的按钮是以编程方式创建的)(我上面的代码来自此处)拖动到我想要继续的场景。我将标识符添加到“editTruck”的序列中。在上面的代码中,performSegueWithIdentifier 有效,但prepareForSegue 无效。没有错误或任何东西它永远不会被调用。

任何帮助将不胜感激。

最佳答案

prepareForSegue:sender 方法移至与 View Controller 中的 editTruck 方法相同的级别。范围的更改将解决您的问题。

iOS 自动调用 View Controller 上的 prepareForSegue:sender 方法,以响应 Storyboard 中的 segue 或通过在代码中调用 performSegueWithIdentifier:sender:

你永远不会自己调用prepareForSegue:sender;您只需在 View Controller 中实现此方法即可。

关于ios - 未在 UIBarButtonItem 选择器内调用prepareForSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31076547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com