Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode/iOS-尝试一个简单的打印到控制台调试,可以';我不能让它工作。不知道如何找到问题_Ios_Iphone_Xcode_Swift_Debugging - Fatal编程技术网

Xcode/iOS-尝试一个简单的打印到控制台调试,可以';我不能让它工作。不知道如何找到问题

Xcode/iOS-尝试一个简单的打印到控制台调试,可以';我不能让它工作。不知道如何找到问题,ios,iphone,xcode,swift,debugging,Ios,Iphone,Xcode,Swift,Debugging,我一直在关注苹果网站上关于T的教程: 请容忍我,因为我以前从未问过iOS开发问题(我才刚刚开始),但到目前为止,这是我的故事板: 触摸(或在本例中单击)红方块将向Xcode调试控制台打印一条消息(请参见下面的代码): ViewController.swift: import UIKit class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavi

我一直在关注苹果网站上关于T的教程:

请容忍我,因为我以前从未问过iOS开发问题(我才刚刚开始),但到目前为止,这是我的故事板:

触摸(或在本例中单击)红方块将向Xcode调试控制台打印一条消息(请参见下面的代码):

ViewController.swift:

    import UIKit

class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    // MARK: Properties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!
    @IBOutlet weak var photoImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Handle the text field’s user input through delegate callbacks.
        nameTextField.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

   // MARK: UITextFieldDelegate
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        // Hide the keyboard.
        textField.resignFirstResponder()
        return true
    }
    func textFieldDidEndEditing(textField: UITextField) {
        mealNameLabel.text = textField.text
    }
   // MARK: UIImagePickerControllerDelegate
    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        // Dismiss the picker if the user canceled.
        dismissViewControllerAnimated(true, completion: nil)
    }
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        // The info dictionary contains multiple representations of the image, and this uses the original.
        let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
        // Set photoImageView to display the selected image.
        photoImageView.image = selectedImage
        // Dismiss the picker.
        dismissViewControllerAnimated(true, completion: nil)
    }
   // MARK: Actions

    @IBAction func selectImageFromPhotoLibrary(sender: UITapGestureRecognizer) {
        // Hide the keyboard.
        nameTextField.resignFirstResponder()
        // UIImagePickerController is a view controller that lets a user pick media from their photo library.
        let imagePickerController = UIImagePickerController()
        // Only allow photos to be picked, not taken.
        imagePickerController.sourceType = .PhotoLibrary
        // Make sure ViewController is notified when the user picks an image.
        imagePickerController.delegate = self
        presentViewController(imagePickerController, animated: true, completion: nil)
    }
    @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }
}
RatingControl.swift:

导入UIKit
类分级控件:UIView{
//标记:初始化
必需的初始化?(编码器aDecoder:NSCoder){
super.init(编码者:aDecoder)
let button=UIButton(帧:CGRect(x:0,y:0,宽度:44,高度:44))
button.backgroundColor=UIColor.redColor()
button.addTarget(self,action:#选择器(RatingControl.ratingButtonTapped(:)),用于控制事件:。触地)
添加子视图(按钮)
}
重写func intrinsicContentSize()->CGSize{
返回CGSize(宽:240,高:44)
}
//标记:按钮动作
功能分级按钮已标记(按钮:UIButton){

打印(“按下按钮我遇到的问题与遵循同一教程完全相同


这就是您需要的:查看>调试区域>激活控制台。(cmd+shift+c)

我遇到的问题与遵循相同教程的问题完全相同


这就是您需要的:视图>调试区域>激活控制台。(cmd+shift+c)

对于发现问题的
XCode v11
+SwiftUI用户,原始海报解释说,您必须在
实时预览中激活
调试
。下面是一个示例,假设您有
视图>调试区域>激活控制台


对于发现问题的
XCode v11
+SwiftUI用户,原始海报解释说,您必须在
实时预览中激活
调试
。下面是一个示例,假设您有
视图>调试区域>激活控制台


如何将分级控制添加到视图中?通过情节提要?我将代码粘贴到测试项目中,当我单击红色方框时,会收到一条控制台消息。在
分级控制上选中
userinteractionenabled
设置为true(在情节提要或代码中)@originaluser2这也是我的第一个想法,但UIView默认为true。如果他们意外关闭了它,仍然值得检查。尝试在
ratingButtonTapped
函数中设置断点,看看是否调用了该函数。Xcode内置了一个非常强大的调试器,可以让您查看应用程序是什么正在做。你应该让自己熟悉它。网上有很多信息。这是我找到的一个视频,你是如何将RatingControl添加到你的视图的?通过故事板?我将你的代码粘贴到一个测试项目中,当我单击红方块时,我会收到一条控制台消息。在
userinteractionenabled上选中
userinteractionenabled
RatingControl
设置为true(在情节提要或代码中)@originaluser2这也是我的第一个想法,但UIView默认为true。如果他们意外关闭了它,仍然值得检查。尝试在
ratingButtonTapped
函数中设置断点,看看是否调用了该函数。Xcode内置了一个非常强大的调试器,可以让您查看应用程序是什么正在做。你应该让自己熟悉它。网上有很多信息。这是我找到的一个视频