【发布时间】:2022-12-03 00:19:30
【问题描述】:
由于某种原因,第二个视图控制器上的按钮不起作用。当我在我的设备上测试代码时,它给我这个错误: 线程 1:“-[DepressionApp1.SecondViewController NextButton]:发送到实例 0x103605560 的无法识别的选择器”
有人能找到错误吗?
这是我的第二个视图控制器的代码
import UIKit
class SecondViewController: UIViewController, UINavigationControllerDelegate{
override func viewDidLoad(){
super.viewDidLoad()
}
@IBAction func nextButton(){
let vc = storyboard?.instantiateViewController(withIdentifier: "third") as! ThirdViewController
vc.modalPresentationStyle = .overFullScreen
present(vc,animated: true)
}
@IBAction func prevbutton(){
let vc = storyboard?.instantiateViewController(withIdentifier: "") as! ViewController
vc.modalPresentationStyle = .overFullScreen
present(vc,animated: true)
}
}
这是我的第一个视图控制器的代码
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageview: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func Btnimagepicker(_ sender: Any) {
let picker = UIImagePickerController()
picker.allowsEditing=true
picker.delegate=self
present(picker, animated:true)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image=info[.editedImage] as? UIImage else {return}
imageview.image=image
dismiss(animated:true)
}
@IBAction func didTapButton(){
let vc = storyboard?.instantiateViewController(withIdentifier: "second") as! SecondViewController
vc.modalPresentationStyle = .fullScreen
present(vc,animated: true)
}
}
这是我的第三个视图控制器的代码
import UIKit
class ThirdViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet weak var Text: UITextView!
/*
// MARK: - Navigation
@IBOutlet weak var Text: UITextView!
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
基本上,第一个视图控制器应该让用户选择图像并转到下一个视图控制器。与第二个视图控制器相比,用户应该能够返回到第一个视图控制器,或者转到第三个视图控制器。
【问题讨论】: