【问题标题】:Error in my next button in second view controller第二个视图控制器中的下一个按钮出错
【发布时间】: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.
    }
    */

}

基本上,第一个视图控制器应该让用户选择图像并转到下一个视图控制器。与第二个视图控制器相比,用户应该能够返回到第一个视图控制器,或者转到第三个视图控制器。

【问题讨论】:

    标签: ios swift xcode


    【解决方案1】:

    确保您的@IBOutlet 已正确连接到笔尖。大多数时候我遇到这样的错误是由于连接丢失或未删除的旧连接。如果您将上传指向存在此问题的项目的链接,将很容易找到并修复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      相关资源
      最近更新 更多